Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
86 lines (70 loc) · 3.04 KB
/
Copy pathmain.py
File metadata and controls
86 lines (70 loc) · 3.04 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import os
import shutil
class Colors:
GREEN = '\033[92m'
RED = '\033[31m'
CYAN = '\033[96m'
BOLD = '\033[1m'
RESET = '\033[0m'
def print_header():
width = 42
line = "=" * width
title = "🧹 Downloads Organizer 🐍"
print(f"{Colors.CYAN}{Colors.BOLD}{line}")
print(f"{title.center(width)}")
print(f"{line}{Colors.RESET}\n")
def choose_dir(directories:list):
print(" [📂] Choose a folder to organize:")
for i, folder in enumerate(directories, 1):
print(f" {i}. ~/{folder}")
while(True):
try:
op = input("\n Number: ")
option = int(op)
if option == 0:
print(" [👋] Exiting...")
exit()
if option > len(directories) or option < 1:
print(f"{Colors.RED} [❌] Invalid number, choose a folder between 1 and {len(directories)}...{Colors.RESET}")
else:
break
except ValueError as e:
print(f"{Colors.RED} [❌] Invalid input! Please enter a number.{Colors.RESET}")
folder = directories[option - 1]
print(f"\n [📍] Chosen: {folder}\n")
return folder
def organize_folder(folder_path):
categories = {
"Images": [".jpg", ".jpeg", ".ico", ".png", ".gif", ".webp", ".jfif", ".svg", ".heic", ".psd", ".ai"],
"Documents": [".pdf", ".docx", ".doc", ".txt", ".xlsx", ".xls", ".pptx", ".csv", ".md", ".mscz", ".rtf", ".odt"],
"Books": [".epub", ".mobi", ".azw3"],
"Executables": [".exe", ".msi", ".deb", ".rpm", ".appimage"],
"Compressed": [".zip", ".rar", ".7z", ".tar", ".gz", ".iso"],
"Videos": [".mp4", ".mkv", ".avi", ".mov", ".wmv", ".flv"],
"Audio": [".mp3", ".wav", ".flac", ".m4a", ".aac", ".ogg"],
"Source": [".ttf", ".otf", ".woff", ".woff2"],
"Code": [".py", ".js", ".html", ".css", ".cpp", ".java", ".kt", ".ipynb", ".ts", ".sql", ".json", ".xml", ".yaml", ".yml", ".sh", ".bat"],
}
print(f" [📍] Path: {folder_path}")
print(f" [⚙️] Starting process...\n")
current_script = os.path.basename(__file__)
for f in os.listdir(folder_path):
if f == current_script:
continue
file_path = os.path.join(folder_path, f)
if os.path.isfile(file_path):
ext = os.path.splitext(f)[1].lower()
for category, extensions in categories.items():
if ext in extensions:
folder = os.path.join(folder_path, category)
if not os.path.exists(folder):
os.makedirs(folder)
shutil.move(file_path, os.path.join(folder, f))
print(f"{Colors.GREEN} [✅] Directory {folder_path} successfully organized. 🧹🐍{Colors.RESET}")
if __name__ == "__main__":
print_header()
home = os.path.expanduser("~")
directories = [d for d in os.listdir(home) if os.path.isdir(os.path.join(home, d))]
folder_name = choose_dir(directories)
folder_path = os.path.join(home, folder_name)
organize_folder(folder_path)