forked from geekcomputers/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Organise.py
193 lines (161 loc) · 5.06 KB
/
Organise.py
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
import os
import sys
import shutil
Music = ['MP3', 'WAV', 'WMA', 'MKA', 'AAC', 'MID', 'RA', 'RAM', 'RM', 'OGG']
Codes = ['CPP', 'RB', 'PY', 'HTML', 'CSS', 'JS']
Compressed = ['RAR', 'JAR', 'ZIP', 'TAR', 'MAR', 'ISO', 'LZ', '7ZIP', 'TGZ', 'GZ', 'BZ2']
Documents = ['DOC', 'DOCX', 'PPT', 'PPTX', 'PAGES', 'PDF', 'ODT', 'ODP', 'XLSX', 'XLS', 'ODS', 'TXT', 'IN', 'OUT', 'MD']
Images = ['JPG', 'JPEG', 'GIF', 'PNG', 'SVG']
Executables = ['LNK','DEB', 'EXE', 'SH', 'BUNDLE']
Video = ['FLV', 'WMV', 'MOV', 'MP4', 'MPEG', '3GP', 'MKV','AVI']
def getVideo():
return Video
def getMusic():
return Music
def getCodes():
return Codes
def getCompressed():
return Compressed
def getImages():
return Images
def getExe():
return Executables
def getDoc():
return Documents
# taking the location of the Folder to Arrange
try:
arrange_dir = str(sys.argv[1])
except IndexError:
arrange_dir = str(raw_input("Enter the Path of directory: "))
# when we make a folder that already exist then WindowsError happen
# changing directory may give WindowsError
def change(direc):
try:
os.chdir(direc)
#print "path changed"
except WindowsError:
print "Error! Cannot change the Directory"
print "Enter a valid directory!"
direc = str(raw_input("Enter the Path of directory: "))
change(direc)
change(arrange_dir)
# now we will get the list of all the directories in the folder
list_dir = os.listdir(os.getcwd())
#print list_dir
#check_Folder = False # for organising Folders
check_Music = False
check_Video = False
check_Exe = False
check_Code = False
check_Compressed = False
check_Img = False
check_Docs = False
main_names = ['Video','Folders','Images','Documents','Music','Codes','Executables','Compressed']
for name in list_dir:
#print name.split('.')
if len(name.split('.')) == 2:
if name.split('.')[1].upper() in getVideo():
try:
os.mkdir("Video")
print "Video Folder Created"
except WindowsError:
print "Images Folder Exists"
old_dir = arrange_dir + "\\" + name
new_dir = arrange_dir + "\Video"
os.chdir(new_dir)
shutil.move(old_dir, new_dir + "\\" + name)
print os.getcwd()
os.chdir(arrange_dir)
#print "It is a folder"
elif name.split('.')[1].upper() in getImages():
try:
os.mkdir("Images")
print "Images Folder Created"
except WindowsError:
print "Images Folder Exists"
old_dir = arrange_dir + "\\" + name
new_dir = arrange_dir + "\Images"
os.chdir(new_dir)
shutil.move(old_dir, new_dir + "\\" + name)
print os.getcwd()
os.chdir(arrange_dir)
#print "It is a folder"
elif name.split('.')[1].upper() in getMusic():
try:
os.mkdir("Music")
print "Music Folder Created"
except WindowsError:
print "Music Folder Exists"
old_dir = arrange_dir + "\\" + name
new_dir = arrange_dir + "\Music"
os.chdir(new_dir)
shutil.move(old_dir, new_dir + "\\" + name)
print os.getcwd()
os.chdir(arrange_dir)
#print "It is a folder"
elif name.split('.')[1].upper() in getDoc():
try:
os.mkdir("Documents")
print "Documents Folder Created"
except WindowsError:
print "Documents Folder Exists"
old_dir = arrange_dir + "\\" + name
new_dir = arrange_dir + "\Documents"
os.chdir(new_dir)
shutil.move(old_dir, new_dir + "\\" + name)
print os.getcwd()
os.chdir(arrange_dir)
#print "It is a folder"
elif name.split('.')[1].upper() in getCodes():
try:
os.mkdir("Codes")
print "Codes Folder Created"
except WindowsError:
print "Codes Folder Exists"
old_dir = arrange_dir + "\\" + name
new_dir = arrange_dir + "\Codes"
os.chdir(new_dir)
shutil.move(old_dir, new_dir + "\\" + name)
print os.getcwd()
os.chdir(arrange_dir)
#print "It is a folder"
elif name.split('.')[1].upper() in getCompressed():
try:
os.mkdir("Compressed")
print "Compressed Folder Created"
except WindowsError:
print "Compressed Folder Exists"
old_dir = arrange_dir + "\\" + name
new_dir = arrange_dir + "\Compressed"
os.chdir(new_dir)
shutil.move(old_dir, new_dir + "\\" + name)
print os.getcwd()
os.chdir(arrange_dir)
#print "It is a folder"
elif name.split('.')[1].upper() in getExe():
try:
os.mkdir("Executables")
print "Executables Folder Created"
except WindowsError:
print "Executables Folder Exists"
old_dir = arrange_dir + "\\" + name
new_dir = arrange_dir + "\Executables"
os.chdir(new_dir)
shutil.move(old_dir, new_dir + "\\" + name)
print os.getcwd()
os.chdir(arrange_dir)
#print "It is a folder"
else:
if name not in main_names:
try:
os.mkdir("Folders")
print "Folders Folder Created"
except WindowsError:
print "Folders Folder Exists"
old_dir = arrange_dir + "\\" + name
new_dir = arrange_dir + "\Folders"
os.chdir(new_dir)
shutil.move(old_dir, new_dir + "\\" + name)
print os.getcwd()
os.chdir(arrange_dir)
print "Done Arranging Files and Folder in your specified directory"