Skip to content

Commit 7a3b855

Browse files
add new category for organize and more extensions
1 parent 2944617 commit 7a3b855

File tree

1 file changed

+42
-7
lines changed

1 file changed

+42
-7
lines changed

Organise-Directory-Files.py

+42-7
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,77 @@
44
dir_path = os.path.dirname(os.path.realpath(__file__))
55

66
try:
7-
print("Organising your files...")
7+
print("Organising your files intro [ images - music - video -executable - archive - torrent - document - code ]")
88
for filename in os.listdir(dir_path):
9-
# Check if files are images
9+
# Check if files are images and you can add more extentions
1010
if filename.lower().endswith((".png", ".jpg", ".jpeg", ".gif", ".bmp", ".pbm", ".pnm")):
11-
# If images folder doesnt exist then create
11+
# If images folder doesnt exist then create new folder
1212
if not os.path.exists("images"):
1313
os.makedirs("images")
1414
shutil.copy2(filename, "images")
1515
os.remove(filename)
1616

17-
# Check if files are music
17+
# Check if files are music and you can add more extentions
1818
if filename.lower().endswith((".wav", ".mp3", ".flac", ".3gp", ".aa", ".aax", ".aiff", ".raw")):
1919
# If music folder doesnt exist then create
2020
if not os.path.exists("music"):
2121
os.makedirs("music")
2222
shutil.copy2(filename, "music")
2323
os.remove(filename)
2424

25+
# Check if files are videos and you can add more extentions
26+
if filename.lower().endswith((".webm", ".mp4")):
27+
# If music folder doesnt exist then create
28+
if not os.path.exists("music"):
29+
os.makedirs("music")
30+
shutil.copy2(filename, "music")
31+
os.remove(filename)
32+
2533
# Check if files are executables
26-
if filename.lower().endswith((".exe", ".tar", ".deb")):
34+
if filename.lower().endswith((".exe", ".msi", ".deb")):
2735
# If executables folder doesnt exist then create
2836
if not os.path.exists("executables"):
2937
os.makedirs("executables")
3038
shutil.copy2(filename, "executables")
3139
os.remove(filename)
3240

41+
# Check if files are archive files
42+
if filename.lower().endswith((".rar", ".tar" , ".zip" , ".gz")):
43+
# If executables folder doesnt exist then create
44+
if not os.path.exists("archives"):
45+
os.makedirs("archives")
46+
shutil.copy2(filename, "archives")
47+
os.remove(filename)
48+
49+
50+
# Check if files are torrent files
51+
if filename.lower().endswith((".torrent",)):
52+
# If executables folder doesnt exist then create
53+
if not os.path.exists("torrent"):
54+
os.makedirs("torrent")
55+
shutil.copy2(filename, "torrent")
56+
os.remove(filename)
57+
3358
# Check if files are documents
34-
if filename.lower().endswith((".txt", ".pdf", ".docx")):
59+
if filename.lower().endswith((".txt", ".pdf", ".docx" , "doc")):
3560
# If executables folder doesnt exist then create
3661
if not os.path.exists("documents"):
3762
os.makedirs("documents")
3863
shutil.copy2(filename, "documents")
3964
os.remove(filename)
4065

66+
67+
# Check if files are code files
68+
if filename.lower().endswith((".py", ".php", ".html" , ".css" , ".js")):
69+
# If executables folder doesnt exist then create
70+
if not os.path.exists("code"):
71+
os.makedirs("code")
72+
shutil.copy2(filename, "code")
73+
os.remove(filename)
74+
75+
4176
except OSError:
42-
print("Error")
77+
print("Error happened ...... try again")
4378
finally:
4479
# When script is finished clear screen and display message
4580
os.system("cls" if os.name == "nt" else "clear")

0 commit comments

Comments
 (0)