-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile_organizer_move.py
More file actions
43 lines (32 loc) · 1.11 KB
/
file_organizer_move.py
File metadata and controls
43 lines (32 loc) · 1.11 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
import os
import shutil
def file_organizer(source):
images = r"C:\Users\user\Desktop\image folder"
text_folder = r"C:\Users\user\Desktop\text folder"
music = r"C:\Users\user\Desktop\music folder"
pdf = r"C:\Users\user\Desktop\pdf folder"
#Create folders if it doesn't exist
if images is not None:
os.makedirs(images, exist_ok=True)
if text_folder is not None:
os.makedirs(text_folder, exist_ok=True)
if music is not None:
os.makedirs(music, exist_ok=True)
if pdf is not None:
os.makedirs(pdf, exist_ok=True)
for file in os.listdir(source):
source_path = os.path.join(source, file)
#Skips subfolders
if os.path.isdir(os.path.join(source, file)):
continue
# Move files by type
if file.endswith(".jpg"):
shutil.move(source_path, images)
elif file.endswith(".docx"):
shutil.move(source_path, text_folder)
elif file.endswith(".mp3"):
shutil.move(source_path, music)
elif file.endswith(".pdf"):
shutil.move(source_path, pdf)
print("Files organized Successfully✅")
file_organizer(r"C:\Users\user\Desktop\file organizer")