Advertisement
Guest User

Untitled

a guest
Jul 29th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "flag"
  5. "fmt"
  6. "github.com/rwcarlsen/goexif/exif"
  7. "log"
  8. "os"
  9. "path"
  10. "path/filepath"
  11. "strings"
  12. )
  13.  
  14. func visit(pathname string, f os.FileInfo, err error) error {
  15. openedFile, err := os.Open(pathname)
  16. if err != nil {
  17. log.Fatal(err)
  18. }
  19.  
  20. exifData, err := exif.Decode(openedFile)
  21. if err != nil {
  22. fmt.Printf("⨯ Unable to load file: %s", pathname)
  23. return nil
  24. }
  25.  
  26. tm, _ := exifData.DateTime()
  27.  
  28. newPathname := strings.ToLower(strings.Replace(pathname, f.Name(), fmt.Sprintf("%s%s", tm.Format("20060102030405"), path.Ext(pathname)), 1))
  29.  
  30. os.Rename(pathname, newPathname)
  31. fmt.Printf("✓ Renaming to: %s\n", strings.Replace(pathname, f.Name(), newPathname, 1))
  32.  
  33. return nil
  34. }
  35.  
  36. func main() {
  37. flag.Parse()
  38. directory := flag.Arg(0)
  39.  
  40. filepath.Walk(directory, visit)
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement