-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
44 lines (38 loc) · 1.3 KB
/
Copy pathmain.py
File metadata and controls
44 lines (38 loc) · 1.3 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
# Libs
from pathlib import Path
import shutil
# Files and their respective folders.
extensions = {
".jpg": "Images",
".jpeg": "Images",
".png": "Images",
".mp4": "Videos",
".pdf": "Documents",
".txt": "Documents",
".zip": "Compacteds",
".rar": "Compacteds",
".py": "Scripts",
".js": "Scripts",
".lua": "Scripts",
".wav": "Sounds",
".mp3": "Sounds"
# You can easily add other extensions!
}
print("Hi! I'm the file organizer. My job is simple:")
print("I take the files from the directory you provide and organize them all into separate folders, like PNG files in an Images folder. Just send me your directory!")
response = input()
directory = Path(response)
for item in directory.iterdir():
if item.is_file():
# Download the file and check its extension.
extension = item.suffix.lower()
folder = extensions.get(extension)
if folder:
destin = directory / folder
# Create the folder if it doesn't exist.
destin.mkdir(exist_ok=True)
# Move the file to the folder.
shutil.move(item, destin / item.name)
print(f"Moved: {item.name} to {folder}")
else:
print(f"File extension not found: {extension}, please add this extension to the code.")