Skip to content

Commit b2f16ac

Browse files
committed
Create main.py
1 parent ceacd84 commit b2f16ac

File tree

1 file changed

+37
-0
lines changed
  • Mini Project/Clear The Clutter

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import os
2+
3+
def createifnotexist(folder):
4+
if not os.path.exists(folder):
5+
os.makedirs(folder)
6+
7+
def moveFiles(folderName, files):
8+
for file in files:
9+
os.replace(file,f"{folderName}/{file}")
10+
11+
12+
if __name__ == "__main__":
13+
14+
files = os.listdir()
15+
files.remove("main.py")
16+
print(files)
17+
createifnotexist("Images")
18+
createifnotexist("Docs")
19+
createifnotexist("Media")
20+
createifnotexist("Others")
21+
imgExts = [".png", ".jpg","jpeg"]
22+
images = [file for file in files if os.path.splitext(file)[1].lower() in imgExts]
23+
24+
doc = [".txt", ".docx",".doc",".pdf"]
25+
docs = [file for file in files if os.path.splitext(file)[1].lower() in doc]
26+
27+
mediaa = [".mp4",".mp3"]
28+
media = [file for file in files if os.path.splitext(file)[1].lower() in mediaa]
29+
others = []
30+
for file in files:
31+
otherexts = os.path.splitext(file)[1].lower()
32+
if (otherexts not in mediaa) and (otherexts not in doc) and (otherexts not in imgExts) and os.path.isfile(file):
33+
others.append(file)
34+
moveFiles("Images",images)
35+
moveFiles("Docs",docs)
36+
moveFiles("Media",media)
37+
moveFiles("Others",others)

0 commit comments

Comments
 (0)