forked from deltanode/File-Organizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileOrganizer.py
95 lines (72 loc) · 3.02 KB
/
FileOrganizer.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import os
import shutil
import re
from tkinter import *
from tkinter import messagebox
current_path=os.getcwd()
#creating filters parameters
lst_images=["png","jpeg","jpg","gif","tiff","eps","psd","ai","indd","raw","ico"]
lst_music = ["mp3","wav","wma","dsd","alac","aac","flac","aiff"]
lst_videos = ["mp4","avi","moc","qt","mkv","avchd","flv","swf"]
lst_documents = ["txt","pdf","doc","docx","csv","xls","xlsx","ppt","pptx","ods","odt","html","htm"]
lst_skip= ["1-Documents","2-Images","3-Music","4-Videos","5-Miscellaneous"]
def create_dir(path):
if not os.path.exists(path):
os.mkdir(path)
def organise(received_path):
path = received_path
os.chdir(path)
# creating directories
create_dir("1-Documents")
create_dir("2-Images")
create_dir("3-Music")
create_dir("4-Videos")
create_dir("5-Miscellaneous")
# moving files in Directories
if __name__ == "__main__":
for i in os.listdir():
f_ext = re.split("[.]",i)[-1] #using re module
# f_ext = os.path.splitext(i)[-1] #using os module
if f_ext in lst_documents:
shutil.move(i,os.path.join(path+"\\1-Documents\\",i))
continue
if f_ext in lst_images:
shutil.move(i,os.path.join(path+"\\2-Images\\",i))
continue
elif f_ext in lst_music:
shutil.move(i,os.path.join(path+"\\3-Music\\",i))
continue
elif f_ext in lst_videos:
shutil.move(i,os.path.join(path+"\\4-Videos\\",i))
continue
elif f_ext in lst_skip:
continue
else:
shutil.move(i,os.path.join(path+"\\5-Miscellaneous\\",i))
def set_path():
path = path_input.get()
# print(path)
organise(path)
## Creating GUI -----------------------------------
root = Tk()
root.title("File Organizer - [YYSCOOP.com]")
root.geometry("635x450")
#root.iconbitmap("images/favicon.ico")
#root.config(bg="white")
background_image = PhotoImage(file=current_path+"\img/a.png")
bg_label = Label(root, image=background_image, width=635)
bg_label.grid(row=0,columnspan=2,sticky=W+N,padx=0)
hfontstyle = ("Helvetica",30,"bold")
path_label = Label(root,text="File Organizer",font=hfontstyle)
path_label.grid(row=0,columnspan=2, sticky=W+N+E)
fontstyle = ("Helvetica",10,"bold")
path_label = Label(root,text="Enter File Location:",font=fontstyle)
path_label.grid(row=2,columnspan=2, sticky=W,padx=5,pady=5)
path_input = Entry(root,width=75,font=fontstyle)
path_input.grid(row=3,column=0, sticky=W, padx=5,pady=5)
submit_btn = Button(root,text="Organise File", command=set_path,fg="white",bg="#f57971")
submit_btn.grid(row=3,column=1,sticky=W,padx=5,pady=5)
ex_fontstyle = ("Helvetica",8,"normal")
path_label = Label(root,text=r"Ex : C:\Users\user\Desktop\doc\folder1\data",font=ex_fontstyle,fg="red")
path_label.grid(row=4,columnspan=2, sticky=W,padx=5)
root.mainloop()