-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile_Organizer.py
More file actions
53 lines (42 loc) · 1.79 KB
/
Copy pathfile_Organizer.py
File metadata and controls
53 lines (42 loc) · 1.79 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
"""
📌 Problem Statement:
Create a Python script that automatically organizes files in a folder by file type,
putting images, documents, videos, etc., into separate subfolders.
"""
import os
import shutil
def organize_folder(folder_path):
# Define file type categories
file_types = {
'Images': ['.jpg', '.jpeg', '.png', '.gif'],
'Documents': ['.pdf', '.docx', '.txt', '.xlsx','.pptx'],
'Videos': ['.mp4', '.avi', '.mkv'],
'Audio': ['.mp3', '.wav'],
'Archives': ['.zip', '.rar',],
'Scripts': ['.py', '.js','.md'],
'Config': ['.ini'],
'Applications': ['.exe']
}
print(f"📂 Organizing files in: {folder_path}\n")
files_moved = 0
# Loop through all files in the folder
for filename in os.listdir(folder_path):
file_path = os.path.join(folder_path, filename)
if os.path.isfile(file_path):
_, ext = os.path.splitext(filename)
moved = False
# Match file extension with category
for folder, extensions in file_types.items():
if ext.lower() in extensions:
target_folder = os.path.join(folder_path, folder)
os.makedirs(target_folder, exist_ok=True) # Create if not exists
shutil.move(file_path, os.path.join(target_folder, filename))
print(f"✅ Moved: {filename} → {folder}/")
files_moved += 1
moved = True
break # Stop checking other categories
if not moved:
print(f"⚠️ Skipped (Unknown type): {filename}")
print(f"\n✨ Done! Total files moved: {files_moved}")
# ✅ Run the function
organize_folder(r"path/to/your/folder")