9
9
"path"
10
10
"path/filepath"
11
11
"strings"
12
+ "github.com/disiqueira/gotree"
12
13
)
13
14
14
15
const (
@@ -19,6 +20,36 @@ var cfg *ini.File
19
20
var cfgFile string
20
21
var language string
21
22
23
+ func addToTree (folder , file string , tree gotree.GTStructure ) gotree.GTStructure {
24
+
25
+ found := false
26
+
27
+ for i , item := range tree .Items {
28
+ if item .Name == folder {
29
+
30
+ var newFile gotree.GTStructure
31
+ newFile .Name = file
32
+
33
+ item .Items = append (item .Items , newFile )
34
+ tree .Items [i ] = item
35
+ }
36
+ }
37
+
38
+ if ! found {
39
+ var newFolder gotree.GTStructure
40
+ var newFile gotree.GTStructure
41
+
42
+ newFolder .Name = folder
43
+ newFile .Name = file
44
+
45
+ newFolder .Items = append (newFolder .Items , newFile )
46
+
47
+ tree .Items = append (tree .Items , newFolder )
48
+ }
49
+
50
+ return tree
51
+ }
52
+
22
53
func main () {
23
54
outputFolder := flag .String ("output" , "." , "Main directory to put organized folders" )
24
55
inputFolder := flag .String ("directory" , "." , "The directory whose files to classify" )
@@ -64,6 +95,10 @@ func main() {
64
95
files , _ := ioutil .ReadDir (* inputFolder )
65
96
fmt .Println ("GOrganizing your Files" )
66
97
98
+ var tree gotree.GTStructure
99
+
100
+ tree .Name = "Files"
101
+
67
102
for _ , f := range files {
68
103
if f .IsDir () {
69
104
continue
@@ -76,18 +111,23 @@ func main() {
76
111
77
112
if len (newFolder ) > 0 {
78
113
79
- folder := filepath .Join (* outputFolder , iniGet ( ext ) )
114
+ folder := filepath .Join (* outputFolder , newFolder )
80
115
newFile := filepath .Join (folder , f .Name ())
81
116
82
- fmt .Println (file + " --> " + newFile )
83
-
84
117
if ! * preview {
85
118
_ = os .Mkdir (folder , os .ModePerm )
86
119
os .Rename (file , newFile )
87
120
}
121
+ } else {
122
+ newFolder = "Unknown extension (will not be moved)"
88
123
}
124
+
125
+ tree = addToTree (newFolder , f .Name (), tree )
126
+
89
127
}
90
128
129
+ gotree .PrintTree (tree )
130
+
91
131
fmt .Println ("All files have been gorganized!" )
92
132
93
133
}
0 commit comments