-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorganize_folder.py
More file actions
55 lines (43 loc) · 1.76 KB
/
Copy pathorganize_folder.py
File metadata and controls
55 lines (43 loc) · 1.76 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
from pathlib import Path
def alchemy_organize(path: str) -> None:
directory = Path(path)
# Define directories for different file types
file_type_dirs = {
'audios': directory / 'audios',
'images': directory / 'images',
'documents': directory / 'documents',
'videos': directory / 'videos',
'others': directory / 'others'
}
# File extensions grouped by type
EXTENSIONS = {
'audios': ['.mp3', '.wav', '.flac', '.aac', '.ogg', '.wma'],
'videos': ['.mp4', '.avi', '.mkv', '.mov', '.wmv', '.flv'],
'images': ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.tiff', '.svg'],
'documents': ['.pdf', '.docx', '.txt', '.xlsx', '.pptx', '.csv', '.md', '.html'],
}
# Create the directories if they don't exist
for folder in file_type_dirs.values():
folder.mkdir(exist_ok=True)
# Get all the files in the directory
file_names = [f for f in directory.iterdir() if f.is_file()]
# Iterate through files and move them to appropriate directories
for file in file_names:
extension = file.suffix.lower()
moved = False
# Check if the file belongs to any of the defined categories
for category, ext_list in EXTENSIONS.items():
if extension in ext_list:
new_folder = file_type_dirs[category]
moved = True
break
# If the file doesn't match any category, move it to 'others'
if not moved:
new_folder = file_type_dirs['others']
# Move the file to the new folder
new_path = new_folder / file.name
file.rename(new_path)
if __name__ == '__main__':
path = input(r'PATH: ')
print(f"Selected path is {path}")
alchemy_organize(path)