-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclean.py
More file actions
50 lines (44 loc) · 2.22 KB
/
Copy pathclean.py
File metadata and controls
50 lines (44 loc) · 2.22 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
import os
import shutil
# Define the path to the current directory
desktop_path = os.getcwd() # Use current working directory
# Categories and their corresponding folder names
categories = {
'.txt': 'Documents', '.docx': 'Documents', '.pdf': 'PDFs', '.doc': 'Documents',
'.rtf': 'Documents', '.odt': 'Documents',
'.jpg': 'Images', '.jpeg': 'Images', '.png': 'Images', '.gif': 'Images',
'.bmp': 'Images', '.tiff': 'Images', '.ico': 'Images', '.svg': 'Images',
'.psd': 'Images', '.ai': 'Images',
'.mp4': 'Videos', '.avi': 'Videos', '.mov': 'Videos', '.wmv': 'Videos',
'.mkv': 'Videos', '.flv': 'Videos', '.m4v': 'Videos', '.webm': 'Videos',
'.3gp': 'Videos', '.mpg': 'Videos', '.mpeg': 'Videos', '.ts': 'Videos', '.vob': 'Videos',
'.xls': 'Spreadsheets', '.xlsx': 'Spreadsheets', '.csv': 'Data',
'.exe': 'Executables', '.bat': 'Executables', '.sh': 'Executables', '.jar': 'Executables',
'.vcf': 'Contacts',
'.ppt': 'Presentations', '.pptx': 'Presentations', '.key': 'Presentations', '.odp': 'Presentations',
'.mp3': 'Audio', '.wav': 'Audio', '.aac': 'Audio', '.ogg': 'Audio', '.flac': 'Audio',
'.zip': 'Archives', '.rar': 'Archives', '.7z': 'Archives', '.tar': 'Archives', '.gz': 'Archives'
}
# Determine which folders are needed
needed_folders = set()
for filename in os.listdir(desktop_path):
file_path = os.path.join(desktop_path, filename)
if os.path.isfile(file_path):
file_ext = os.path.splitext(filename)[1].lower() # Ensure case insensitivity
folder_name = categories.get(file_ext)
if folder_name:
needed_folders.add(folder_name)
# Create only the needed folders
for folder in needed_folders:
folder_path = os.path.join(desktop_path, folder)
if not os.path.exists(folder_path):
os.makedirs(folder_path)
# Move files into corresponding folders
for filename in os.listdir(desktop_path):
file_path = os.path.join(desktop_path, filename)
if os.path.isfile(file_path):
file_ext = os.path.splitext(filename)[1].lower() # Ensure case insensitivity
folder_name = categories.get(file_ext)
if folder_name:
shutil.move(file_path, os.path.join(desktop_path, folder_name, filename))
print("Desktop cleaned!")