-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
40 lines (35 loc) · 1.14 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
import os
import shutil
ImgExts = [".jpg", ".jpeg", ".bmp", ".png"]
DocExts = [".txt", ".doc", ".docx", ".pdf"]
OfficeExts = [".xlsx", ".pptx", ".accdb"]
MediaExts = [".mp4", ".mp3", ".m4a", ".flv", ".mkv", ".avi"]
CodeExts = [".py", ".java", ".c", ".js"]
def createFolder(foldername):
if not os.path.exists(foldername):
os.makedirs(foldername)
createFolder('Images')
createFolder('Docs')
createFolder('Office')
createFolder('Media')
createFolder('Code')
createFolder('Others')
contents = os.listdir()
contents.remove("main.py")
files = []
for content in contents:
if os.path.isfile(content):
files.append(content)
for file in files:
if os.path.splitext(file)[1].lower() in ImgExts:
shutil.move(file, 'Images')
elif os.path.splitext(file)[1].lower() in DocExts:
shutil.move(file, 'Docs')
elif os.path.splitext(file)[1].lower() in OfficeExts:
shutil.move(file, 'Office')
elif os.path.splitext(file)[1].lower() in MediaExts:
shutil.move(file, 'Media')
elif os.path.splitext(file)[1].lower() in CodeExts:
shutil.move(file, 'Code')
else:
shutil.move(file, 'Others')