Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "flag"
  5. "os"
  6. "path/filepath"
  7. "strings"
  8. )
  9.  
  10. var files []string
  11. var t string
  12.  
  13. func visit(path string, f os.FileInfo, err error) error {
  14. if strings.Contains(path, t) {
  15. files = append(files, path)
  16. }
  17. return nil
  18. }
  19.  
  20. func main() {
  21. var parentDir = flag.String("p", "", "Parent Directory")
  22. var fileType = flag.String("t", "", "File types target")
  23. flag.Parse()
  24. if *parentDir != "" && *fileType != "" {
  25. t = *fileType
  26. err := filepath.Walk(*parentDir, visit)
  27. if err != nil {
  28. panic(err)
  29. }
  30. for _, f := range files {
  31. os.Rename(f, *parentDir)
  32.  
  33. }
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement