-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
68 lines (61 loc) · 1.99 KB
/
main.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
import os
import sys
import shutil
import exts
def organize_folder(folder):
files = set(os.listdir(folder))
if files == []:
return
if "Audio" not in files:
os.mkdir(folder+"/Audio")
if "Video" not in files:
os.mkdir(folder+"/Video")
if "Documents" not in files:
os.mkdir(folder+"/Documents")
if "Softwares" not in files:
os.mkdir(folder+"/Softwares")
if "Compressed" not in files:
os.mkdir(folder+"/Compressed")
if "Pictures" not in files:
os.mkdir(folder+"/Pictures")
if "Other" not in files:
os.mkdir(folder+"/Other")
for file in files:
extension = os.path.splitext(file)[1]
if extension == "":
continue
else:
extension = extension.lower()
if extension in exts.audio:
shutil.move(folder+"/"+file, folder+"/Audio")
elif extension in exts.video:
shutil.move(folder+"/"+file, folder+"/Video")
elif extension in exts.docs:
shutil.move(folder+"/"+file, folder+"/Documents")
elif extension in exts.soft:
shutil.move(folder+"/"+file, folder+"/Softwares")
elif extension in exts.comp:
shutil.move(folder+"/"+file, folder+"/Compressed")
elif extension in exts.images:
shutil.move(folder+"/"+file, folder+"/Pictures")
else:
shutil.move(folder+"/"+file, folder+"/Other")
def validate(folder):
if (os.path.splitext(folder)[1] != ""):
print("hhh")
return 0
else:
if(folder[len(folder)-1] == '/' or folder[len(folder)-1] == '\\'):
folder = folder[0:len(folder)-1]
return folder
if __name__ == '__main__':
l = len(sys.argv)
if l == 1:
organize_folder(os.cwd())
else:
q = 1
while q != l:
val = validate(sys.argv[q])
if(val != 0):
organize_folder(val)
q += 1