-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
46 lines (39 loc) · 1.13 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main
import (
"fmt"
"os"
"strings"
)
type FileMove struct {
From string
To string
}
func main() {
if len(os.Args) < 2 {
fmt.Println("Usage: go run program.go <directory_path> <destination_path>")
return
}
root := os.Args[1] // get the directory path from the command line
if strings.HasSuffix(root, "/") {
root = root[:len(root)-1]
}
if len(os.Args) < 3 {
fmt.Println("Usage: go run program.go <directory_path> <destination_path>")
return
}
destination := os.Args[2] // get the directory path from the command line
if strings.HasSuffix(destination, "/") {
destination = destination[:len(destination)-1]
}
// First we just walk the directory tree and list all of the files we have.
filesToMove, err := listAllFiles(root)
if err != nil {
fmt.Printf("walk error [%v]\n", err)
}
// Now the filesToMove are a list of files. Next we might want to update the destination of the files...
fixFilesToMove(&filesToMove, root)
// Now we can either copy the files to the destination, or update them and write them out
for _, f := range filesToMove {
visitFile(root, destination, f.From, f.To, filesToMove)
}
}