Skip to content
This repository was archived by the owner on Apr 24, 2025. It is now read-only.

Commit 4042f93

Browse files
committed
Organizer the files in the directory you want
1 parent 074a933 commit 4042f93

1 file changed

Lines changed: 82 additions & 0 deletions

File tree

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import os
2+
import shutil
3+
4+
def main():
5+
dir_path = input("Enter the directory path of the files: ")
6+
7+
try:
8+
print("Organising your files into [ images - music - video - executable - archive - torrent - document - code - design files]")
9+
for filename in os.listdir(dir_path):
10+
absname = os.path.join(dir_path, filename)
11+
# Check if files are images and you can add more extensions
12+
if filename.lower().endswith((".png", ".jpg", ".jpeg", ".gif", ".bmp", ".pbm", ".pnm")):
13+
# If images folder doesn't exist then create new folder
14+
if not os.path.exists("images"):
15+
os.makedirs("images")
16+
shutil.move(absname, "images")
17+
18+
# Check if files are music and you can add more extensions
19+
elif filename.lower().endswith((".wav", ".mp3", ".flac", ".3gp", ".aa", ".aax", ".aiff", ".raw")):
20+
# If music folder doesn't exist then create new folder
21+
if not os.path.exists("music"):
22+
os.makedirs("music")
23+
shutil.move(absname, "music")
24+
25+
# Check if files are videos and you can add more extensions
26+
elif filename.lower().endswith((".webm", ".mp4")):
27+
# If video folder doesn't exist then create new folder
28+
if not os.path.exists("video"):
29+
os.makedirs("video")
30+
shutil.move(absname, "video")
31+
32+
# Check if files are executables
33+
elif filename.lower().endswith((".exe", ".msi", ".deb" , "dmg")):
34+
# If executables folder doesn't exist then create new folder
35+
if not os.path.exists("executables"):
36+
os.makedirs("executables")
37+
shutil.move(absname, "executables")
38+
39+
# Check if files are archive files
40+
elif filename.lower().endswith((".rar", ".tar" , ".zip" , ".gz")):
41+
# If archive folder doesn't exist then create new folder
42+
if not os.path.exists("archives"):
43+
os.makedirs("archives")
44+
shutil.move(absname, "archives")
45+
46+
# Check if files are torrent files
47+
elif filename.lower().endswith((".torrent",)):
48+
# If torrent folder doesn't exist then create new folder
49+
if not os.path.exists("torrent"):
50+
os.makedirs("torrent")
51+
shutil.move(absname, "torrent")
52+
53+
# Check if files are documents
54+
elif filename.lower().endswith((".txt", ".pdf", ".docx" , "doc")):
55+
# If documents folder doesn't exist then create new folder
56+
if not os.path.exists("documents"):
57+
os.makedirs("documents")
58+
shutil.move(absname, "documents")
59+
60+
# Check if files are code files
61+
elif filename.lower().endswith((".py", ".php", ".html" , ".css" , ".js")):
62+
# If code folder doesn't exist then create new folder
63+
if not os.path.exists("code"):
64+
os.makedirs("code")
65+
shutil.move(absname, "code")
66+
67+
# Check if files are design files
68+
elif filename.lower().endswith((".psd", ".ai")):
69+
# If design folder doesn't exist then create new folder
70+
if not os.path.exists("design-files"):
71+
os.makedirs("design-files")
72+
shutil.move(absname, "design-files")
73+
74+
except OSError:
75+
print("Error happened ...... try again")
76+
finally:
77+
# When script is finished clear screen and display message
78+
os.system("cls" if os.name == "nt" else "clear")
79+
print("Finished organising your files")
80+
81+
if __name__ == "__main__":
82+
main()

0 commit comments

Comments
 (0)