-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile_organizer.py
43 lines (35 loc) · 1.27 KB
/
file_organizer.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
import os
import shutil
path_name = input(r'Enter File Address')
def organize(path_name):
os.chdir(path_name)
directory = os.listdir(path_name)
extensions = {
'.txt': 'Text Files',
'.pdf': 'PDFs',
'.jpg': 'Images',
'.png': 'Images',
'.xlsx': 'Spreadsheets',
'.docx': 'Documents',
'.mp3': 'Music',
'.mp4': 'Videos',
'.mkv':'Videos',
'.zip' : 'Zip Files',
'.exe' : 'Software Setups',
'.srt':'Videos'
# Add more file extensions and folder names as needed
}
split_files = []
ext= []
filename = []
# splits the files into their filenames and extensions
for filename in os.listdir(path_name):
file = os.path.join(path_name , filename)
if os.path.isfile(file):
_,file_ext = os.path.splitext(filename)
if file_ext.lower() in extensions:
new_directory = os.path.join(path_name, extensions[file_ext.lower()])
os.makedirs(new_directory,exist_ok=True)
shutil.move(filename, os.path.join(new_directory, filename))
print(f"Moved {filename} to {new_directory}")
p= organize(r'C:\Users\hp\Downloads\New folder\New folder')