-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorganize.py
More file actions
34 lines (31 loc) · 982 Bytes
/
organize.py
File metadata and controls
34 lines (31 loc) · 982 Bytes
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
import os
import shutil
from pathlib import Path
# Set your desktop path
desktop = Path.home() / "Desktop"
# File categories
categories = {
"Images": [".jpg", ".jpeg", ".png", ".gif"],
"Documents": [".pdf", ".docx", ".txt"],
"Zips": [".zip", ".rar"],
"Code": [".py", ".js", ".html"],
"Videos": [".mp4", ".mov"],
"Others": []
}
def organize():
for file in desktop.iterdir():
if file.is_file():
moved = False
for folder, extensions in categories.items():
if file.suffix.lower() in extensions:
move_file(file, desktop / folder)
moved = True
break
if not moved:
move_file(file, desktop / "Others")
def move_file(file, destination):
destination.mkdir(exist_ok=True)
shutil.move(str(file), str(destination / file.name))
print(f"Moved: {file.name} → {destination}")
if __name__ == "__main__":
organize()