-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
41 lines (29 loc) · 1.12 KB
/
main.py
File metadata and controls
41 lines (29 loc) · 1.12 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
import os
def createIfNotExist(folder):
if not os.path.exists(folder):
os.makedirs(folder)
def move(folderName, files):
for file in files:
os.replace(file, f"{folderName}/{file}")
if __name__ == "__main__":
files = os.listdir()
files.remove("main.py")
createIfNotExist('Images')
createIfNotExist('Docs')
createIfNotExist('Media')
createIfNotExist('Others')
imgExts = [".png", ".jpg", ".jpeg"]
images = [file for file in files if os.path.splitext(file)[1].lower() in imgExts ]
docExts = [".txt", ".docx", "doc", ".pdf"]
docs = [file for file in files if os.path.splitext(file)[1].lower() in docExts]
mediaExts = [".mp4", ".mp3", ".flv"]
medias = [file for file in files if os.path.splitext(file)[1].lower() in mediaExts]
others = []
for file in files:
ext = os.path.splitext(file)[1].lower()
if (ext not in mediaExts) and (ext not in docExts) and (ext not in imgExts) and os.path.isfile(file):
others.append(file)
move("Images", images)
move("Docs", docs)
move("Media", medias)
move("Others", others)