Work on media-parsing
This commit is contained in:
35
main.go
35
main.go
@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -17,9 +18,43 @@ func main() {
|
||||
fallthrough
|
||||
case "rs":
|
||||
suffix := args[1]
|
||||
removeSuffix(suffix)
|
||||
break
|
||||
default:
|
||||
fmt.Println("Invalid action specified")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func removeSuffix(suffix string) {
|
||||
filepath.Walk(".", removeSuffixFunc(suffix))
|
||||
}
|
||||
|
||||
func removeSuffixFunc(suffix string) filepath.WalkFunc {
|
||||
return func(p string, f os.FileInfo, err error) error {
|
||||
filename := f.Name()
|
||||
if filename == "." || filename == ".." {
|
||||
return nil
|
||||
}
|
||||
|
||||
element := newMediaElement(p)
|
||||
fmt.Println(element.String())
|
||||
|
||||
dir := filepath.Dir(p)
|
||||
ext := filepath.Ext(filename)
|
||||
filenameNoExt := trimSuffix(filename, ext)
|
||||
filenameNoSuff := trimSuffix(filenameNoExt, suffix)
|
||||
if filenameNoSuff != filenameNoExt {
|
||||
newFilename := filenameNoSuff + ext
|
||||
|
||||
err := os.Rename(filepath.Join(dir, filename), filepath.Join(dir, newFilename))
|
||||
if err != nil {
|
||||
fmt.Printf("Could not rename %s: %v\n", filename, err)
|
||||
} else {
|
||||
fmt.Println("Renamed " + filename + " to " + newFilename)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user