-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
104 lines (83 loc) · 3.46 KB
/
main.py
File metadata and controls
104 lines (83 loc) · 3.46 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import argparse
import sys
import platform
import os
from colorama import init, Fore, Style
from organizer import FileOrganizer
# Initialize colorama for cross-platform colored output
init(autoreset=True)
def get_os_info():
"""
Detects the operating system and specific Linux distribution.
"""
system = platform.system()
if system == "Windows":
return "Windows"
elif system == "Linux":
# Try to detect specific Linux distro via /etc/os-release
try:
with open("/etc/os-release", "r") as f:
info = f.read().lower()
if "id=ubuntu" in info or "id_like=ubuntu" in info:
return "Ubuntu Linux"
elif "id=arch" in info or "id_like=arch" in info:
return "Arch Linux"
elif "id=fedora" in info or "id_like=fedora" in info:
return "Fedora Linux"
elif "id=debian" in info:
return "Debian Linux"
else:
return "Linux (Generic)"
except FileNotFoundError:
return "Linux"
elif system == "Darwin":
return "macOS"
return "Unknown OS"
def print_banner():
current_os = get_os_info()
print(Fore.CYAN + Style.BRIGHT + "=" * 50)
print(Fore.YELLOW + " 📂 SORTIFY - File Organizer ")
print(Fore.CYAN + "=" * 50)
print(Fore.MAGENTA + f"🖥️ System Detected: {Style.BRIGHT}{current_os}")
print(Fore.CYAN + "=" * 50 + "\n")
def main():
print_banner()
target_path = ""
# 1. Check if path was passed as a command line argument
if len(sys.argv) > 1:
target_path = sys.argv[1]
else:
# 2. If no argument, ask the user interactively
print(Fore.WHITE + "Which folder do you want to organize?")
print(Fore.WHITE + "(Enter '.' for current directory or paste full path)")
try:
user_input = input(Fore.GREEN + "📍 Enter Path: " + Style.RESET_ALL).strip()
# Remove quotes if the user dragged and dropped the folder into terminal
target_path = user_input.strip('"').strip("'")
if target_path == "":
target_path = "."
except KeyboardInterrupt:
print(Fore.RED + "\n\n🚫 Operation cancelled by user.")
sys.exit()
print(f"\n{Fore.BLUE}⚙️ Processing path: {Style.BRIGHT}{os.path.abspath(target_path)}...\n")
try:
organizer = FileOrganizer(target_path)
stats = organizer.organize()
print(Fore.GREEN + "✅ Organization Complete!\n")
print(Fore.WHITE + "📊 Summary:")
total_moved = 0
for category, count in stats.items():
if count > 0:
print(f" - {category}: {Fore.YELLOW}{count}{Fore.WHITE} files moved")
total_moved += 1
if total_moved == 0:
print(Fore.RED + " ⚠️ No files needed moving (or folder is empty).")
except FileNotFoundError:
print(Fore.RED + f"❌ Error: The directory '{target_path}' was not found.")
print(Fore.RED + " Please check the path and try again.")
except PermissionError:
print(Fore.RED + "❌ Error: Permission denied. Try running as Administrator/Sudo.")
except Exception as e:
print(Fore.RED + f"❌ An unexpected error occurred: {e}")
if __name__ == "__main__":
main()