-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPython_1st_project(File separator program).py
More file actions
35 lines (31 loc) · 1.27 KB
/
Copy pathPython_1st_project(File separator program).py
File metadata and controls
35 lines (31 loc) · 1.27 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
import os, shutil
#Dictionary
defined_extension = {
'audio_extension': ('.mp3', '.wav', '.aif', '.cda'),
'video_extension': ('.mp4', '.mov', '.wmv', '.flv', '.avi'),
'document_extension': ('.docx', '.pdf', '.tex', '.txt', '.vtt', '.xlsx'),
'image_extension': ('.jpeg', '.png', '.jpg')
}
User_folder_path = input("Enter Path:")
def files_finder(folder_path, folder_extension):
files_list = []
for file in os.listdir(folder_path):
for extension in folder_extension:
if file.endswith(extension):
files_list.append(file)
return files_list
for extension_type, extension_tuple in defined_extension.items():
folder_name = extension_type.split('_')[0] + 'Files'
folder_path = os.path.join(User_folder_path, folder_name)
#checking if file is already exist or not.
if os.path.exists(folder_path):
pass
else:
os.mkdir(folder_path)
if files_finder(User_folder_path, extension_tuple) == 0:
os.rmdir(folder_path)
else:
for item in files_finder(User_folder_path, extension_tuple):
item_path = os.path.join(User_folder_path, item)
item_new_path = os.path.join(folder_path, item)
shutil.move(item_path, item_new_path)