Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "flag"
- "fmt"
- "github.com/rwcarlsen/goexif/exif"
- "log"
- "os"
- "path"
- "path/filepath"
- "strings"
- )
- func visit(pathname string, f os.FileInfo, err error) error {
- openedFile, err := os.Open(pathname)
- if err != nil {
- log.Fatal(err)
- }
- exifData, err := exif.Decode(openedFile)
- if err != nil {
- fmt.Printf("⨯ Unable to load file: %s", pathname)
- return nil
- }
- tm, _ := exifData.DateTime()
- newPathname := strings.ToLower(strings.Replace(pathname, f.Name(), fmt.Sprintf("%s%s", tm.Format("20060102030405"), path.Ext(pathname)), 1))
- os.Rename(pathname, newPathname)
- fmt.Printf("✓ Renaming to: %s\n", strings.Replace(pathname, f.Name(), newPathname, 1))
- return nil
- }
- func main() {
- flag.Parse()
- directory := flag.Arg(0)
- filepath.Walk(directory, visit)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement