-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsorter.py
More file actions
70 lines (57 loc) · 1.74 KB
/
sorter.py
File metadata and controls
70 lines (57 loc) · 1.74 KB
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
import shutil
import os
'''
Folders and Extensions:
Documents - doc,docx,txt,pdf
Video - mkv,mp4,webm,mov,avi,m4v
Audio - mp3,wav,flac,
Images - psd,jpg,png,tiff,bmp,
Zip Files - zip,rar,7z,iso
Code - html,css,py,js,php,rb,xml,json,pyw,c,sh,bat,cs,java
Other
Folders
'''
extensions = {
"Documents": ["doc", "docx", "txt", "pdf"],
"Video": ["mkv", "mp4", "webm", "mov", "avi", "m4v"],
"Audio": ["mp3", "wav", "flac"],
"Images": ["psd", "jpg", "png", "tiff", "bmp"],
"Zip Files": ["zip", "rar", "7z", "iso"],
"Code": ["html", "css", "py", "js", "php", "rb", "xml",
"json", "pyw", "c", "sh", "bat", "cs", "java"],
"Folders": [],
"Other": []
}
def sort_files(path, extensions):
files = os.listdir(path)
try:
for folder in extensions.keys():
os.mkdir(folder)
except FileExistsError:
pass
dont_Touch = extensions.keys()
for file in files:
try:
is_found = False
ext = os.path.splitext(file)[1]
ext = ext[1:]
if os.path.isdir(file):
if file in dont_Touch:
pass
else:
shutil.move(file, "Folders")
else:
for key, value in extensions.items():
if os.path.splitext(file)[0] == "sorter":
is_found = True
raise Exception()
elif ext in value:
shutil.move(file, key)
is_found = True
raise Exception()
if not is_found:
shutil.move(file, "Other")
raise Exception()
except:
pass
sort_files(r".", extensions)