File utils library for Golang projects.
Execute io commands based on the destination and source path.
package main
import (
"github.com/alancesar/tidy-file/command"
"os"
)
func main() {
sourcePath := "source/path"
destinationPath := "destination/path"
command.
NewExecutor(sourcePath, destinationPath).
Execute(command.MkDirCommand, os.Rename)
}
Check MIME types from files.
package main
import (
"fmt"
"github.com/alancesar/tidy-file/mime"
)
func main() {
path := "source/path/audio.mp3"
if mime.Is(path, mime.AudioType) {
fmt.Printf("%s is an audio file", path)
}
}
Look for a specific file type in a directory and its sub directories.
package main
import (
"fmt"
"github.com/alancesar/tidy-file/mime"
"github.com/alancesar/tidy-file/path"
)
func main() {
root := "source/root"
images := path.LookFor(root, mime.ImageType)
for _, image := range images {
fmt.Printf("%s is an image file", image)
}
}
creates a path from an interface{} based on a pattern using text/template engine.
package main
import (
"fmt"
"github.com/alancesar/tidy-file/path"
)
func main() {
myStruct := struct {
Track int
Title string
Artist string
Album string
Year int
}{
Track: 7,
Title: "Basket Case",
Artist: "Green Day",
Album: "Dookie",
Year: 1994,
}
output, _ := path.NewBuilder().
FromPattern("{{.Artist}}/[{{.Year}}] {{.Album}}/{{printf \"%02d\" .Track}} - {{.Title}}", myStruct)
// "Green Day/[1994] Dookie/07 - Basket Case"
fmt.Printf(output)
}