-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
25 lines (19 loc) · 731 Bytes
/
Copy pathmain.py
File metadata and controls
25 lines (19 loc) · 731 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
import os,shutil
path = r"C:\Users\mhady\PycharmProjects\FileSorter\TestFolder"
file_names = os.listdir(path)
folder_names = ['excel_files','txt_files','image_files']
#print(os.getcwd())
os.chdir(path)
#print(os.getcwd())
for folder_name in folder_names:
if os.path.exists(folder_name):
pass
else:
os.mkdir(folder_name)
for file in file_names:
if ".xlsx" in file and file not in os.listdir(path+"\excel_files"):
shutil.move(file,path+"\excel_files")
elif ".txt" in file and file not in os.listdir(path+"\\"+"txt_files"):
shutil.move(file,path+"\\txt_files")
elif ".jpg" in file and file not in os.listdir(path+"\image_files"):
shutil.move(file,path+"\image_files")