-
Notifications
You must be signed in to change notification settings - Fork 0
/
fileorg-v2.py
52 lines (45 loc) · 2.13 KB
/
fileorg-v2.py
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
import os
import shutil
# Define the target folder
target_folder = 'C:/Users/Samsung/Downloads'
# Define categories and their respective extensions
categories = {
'Pictures': ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'tiff', 'svg'],
'Videos': ['mp4', 'mov', 'wmv', 'flv', 'avi', 'mkv'],
'Documents': ['pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'txt', 'odt'],
'Music': ['mp3', 'wav', 'aac', 'flac', 'ogg'],
'Archives': ['zip', 'rar', '7z', 'tar', 'gz'],
'Scripts': ['py', 'js', 'html', 'css'],
'Others': []
}
# Define destination paths for each category
destination_paths = {
'Pictures': 'C:/Users/Public/Pictures',
'Documents': 'C:/Users/Public/Documents',
'Videos': 'C:/Users/Samsung/Videos', # Adjust path as needed
'Music': 'C:/Users/Samsung/Music', # Adjust path as needed
'Archives': 'C:/Users/Public/Documents', # Send to Documents
'Scripts': 'C:/Users/Public/Documents', # Send to Documents
'Others': 'C:/Users/Public/Documents' # Send to Documents
}
# Create folders for each category if they don't exist
for category, path in destination_paths.items():
if not os.path.exists(path):
os.makedirs(path)
# Function to categorize and move files
def categorize_and_move_files(target_folder, categories, destination_paths):
for item in os.listdir(target_folder):
if os.path.isfile(os.path.join(target_folder, item)):
file_extension = item.split('.')[-1].lower()
moved = False
for category, extensions in categories.items():
if file_extension in extensions:
shutil.move(os.path.join(target_folder, item), os.path.join(destination_paths[category], item))
moved = True
break
# Move to 'Others' if the file type doesn't match any category
if not moved:
shutil.move(os.path.join(target_folder, item), os.path.join(destination_paths['Others'], item))
# Call the function to categorize and move files
categorize_and_move_files(target_folder, categories, destination_paths)
print("Files have been categorized and moved successfully.")