Skip to content

Commit 0b471e3

Browse files
Added file organiser script
1 parent ba54b32 commit 0b471e3

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

file-organiser/organise.py

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import os
2+
import shutil
3+
4+
dir_path = os.path.dirname(os.path.realpath(__file__))
5+
6+
try:
7+
print("Organising your files...")
8+
for filename in os.listdir(dir_path):
9+
# Check if files are images
10+
if filename.lower().endswith((".png", ".jpg", ".jpeg", ".gif", ".bmp", ".pbm", ".pnm")):
11+
# If images folder doesnt exist then create
12+
if not os.path.exists("images"):
13+
os.makedirs("images")
14+
shutil.copy2(filename, "images")
15+
os.remove(filename)
16+
17+
# Check if files are music
18+
if filename.lower().endswith((".wav", ".mp3", ".flac", ".3gp", ".aa", ".aax", ".aiff", ".raw")):
19+
# If music folder doesnt exist then create
20+
if not os.path.exists("music"):
21+
os.makedirs("music")
22+
shutil.copy2(filename, "music")
23+
os.remove(filename)
24+
25+
# Check if files are executables
26+
if filename.lower().endswith((".exe", ".tar", ".deb")):
27+
# If executables folder doesnt exist then create
28+
if not os.path.exists("executables"):
29+
os.makedirs("executables")
30+
shutil.copy2(filename, "executables")
31+
os.remove(filename)
32+
33+
# Check if files are documents
34+
if filename.lower().endswith((".txt", ".pdf", ".docx")):
35+
# If executables folder doesnt exist then create
36+
if not os.path.exists("documents"):
37+
os.makedirs("documents")
38+
shutil.copy2(filename, "documents")
39+
os.remove(filename)
40+
41+
except OSError:
42+
print("Error")
43+
finally:
44+
# When script is finished clear screen and display message
45+
os.system("cls" if os.name == "nt" else "clear")
46+
print("Finished organising your files")

0 commit comments

Comments
 (0)