-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
102 lines (84 loc) · 3.06 KB
/
main.py
File metadata and controls
102 lines (84 loc) · 3.06 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
import json
import sys
from pathlib import Path
from colorama import Fore, Style, init
init(autoreset=True)
def load_settings():
default_settings = {
"language": "en",
"text_color": "white",
"folders": {
"Images": [".png", ".jpg", ".jpeg", ".webp"],
"Documents": [".docx", ".doc", ".pdf", ".txt"],
"Videos": [".mp4", ".mov", ".mkv", ".avi"],
"Music": [".mp3", ".wav"]
}
}
settings_path = Path("Settings.json")
if settings_path.exists():
try:
with open(settings_path, 'r', encoding='utf-8') as f:
return json.load(f)
except Exception:
return default_settings
return default_settings
def get_color(color_name):
colors = {
"white": Fore.WHITE,
"red": Fore.RED,
"green": Fore.GREEN,
"blue": Fore.BLUE,
"yellow": Fore.YELLOW,
"cyan": Fore.CYAN,
"magenta": Fore.MAGENTA
}
return colors.get(color_name.lower(), Fore.WHITE)
def main():
settings = load_settings()
lang = settings.get("language", "en")
text_color = get_color(settings.get("text_color", "white"))
messages = {
"en": {
"input": "Enter the path to the folder: ",
"empty": "Error: Path cannot be empty!",
"not_found": "Error: Path does not exist!",
"done": "Success: Sorting completed!"
},
"ru": {
"input": "Введите путь к папке: ",
"empty": "Ошибка: Путь не может быть пустым!",
"not_found": "Ошибка: Путь не существует!",
"done": "Готово: Сортировка завершена!"
}
}
msg = messages.get(lang, messages["en"])
print(text_color + msg["input"], end="")
target_path_str = input().strip()
if not target_path_str:
print(Fore.RED + msg["empty"])
sys.exit()
target_dir = Path(target_path_str)
if not target_dir.exists() or not target_dir.is_dir():
print(Fore.RED + msg["not_found"])
sys.exit()
config_folders = settings.get("folders", {})
for file in target_dir.iterdir():
if file.is_file():
file_ext = file.suffix.lower()
for folder_name, extensions in config_folders.items():
if file_ext in extensions:
dest_folder = target_dir / folder_name
dest_folder.mkdir(exist_ok=True)
new_file_path = dest_folder / file.name
counter = 1
while new_file_path.exists():
new_file_path = dest_folder / f"{file.stem} ({counter}){file.suffix}"
counter += 1
try:
file.replace(new_file_path)
except Exception:
pass
break
print(text_color + msg["done"])
if __name__ == "__main__":
main()