Added Py_Cleaner (#162)

* Update README.md

* Added Py_Cleaner
This commit is contained in:
Abhishek 2020-10-05 13:24:15 +05:30 committed by GitHub
parent 3a41510cf5
commit 0a2ceccb4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 181 additions and 0 deletions

26
Py_Cleaner/README.md Normal file
View File

@ -0,0 +1,26 @@
# PY-CLEAN
Tool to organize Directories
### Installations and Dependencies
-> [Python](https://python.org) Installed
### How to execute the file:
1. Windows Users: Open CMD/ Powershell -> Navigate to the Cloned Directory and then Type In:
```python
python main.py
```
2. OSX/ Linux: Open Terminal -> Navigate to the Cloned Directory and then Type In:
```python
python3 main.py
```
### Note
-> Kindly do not modify any file (unless you know what you are doing).

Binary file not shown.

After

Width:  |  Height:  |  Size: 151 KiB

BIN
Py_Cleaner/bg.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 634 KiB

BIN
Py_Cleaner/folder.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

154
Py_Cleaner/main.py Normal file
View File

@ -0,0 +1,154 @@
# Required Imports
import os
import shutil
import sys
from tkinter import *
import tkinter.messagebox as tmsg
from tkinter import filedialog
### File Extensions
exts = {
'Images' : ['.jpeg', '.jpg', '.png', '.gif', '.bmp', '.ico', '.svg', '.tff'],
'Medias' : ['.mp4', '.mp3', '.mkv', '.mov', '.3gp', '.wav', '.wmv', '.aac', '.flv', '.webm'],
'Docs' : ['.pdf', '.docx', '.doc', '.pptx', '.pages', '.key', '.txt', '.rtf', '.csv', '.xlsx', '.odt', '.ppt'],
'Codes' : ['.py', '.pyc', '.dart', '.c', '.cpp', '.js', '.html', '.css', '.java', '.go', '.r', '.sh'],
'Archives' : ['.rar', '.zip', '.7z', '.alzip', '.iso', '.dmg'],
'Executables' : ['.exe', '.bat', '.command', '.apk', '.app']
}
def create_folder(folder_name):
''' Create Folder if does not exists '''
if not os.path.exists(folder_name):
os.makedirs(folder_name)
def select_folder():
''' File Dialog Folder Selection '''
file_path = filedialog.askdirectory()
path.set(file_path)
def clean_dir():
''' Organize the directory '''
try:
entry_path = path.get() # This path is extracted from entry widget
if (entry_path != ''):
if (os.path.isdir(entry_path)):
os.chdir(entry_path)
cwd_files = [file.lower() for file in os.listdir(os.getcwd())] # Get the CWD files
file_name = os.path.basename(sys.argv[0]) # Extract name of the script
if os.path.isfile(file_name): # Exclude the main script in the cleaning process if it exists in the CWD
cwd_files.remove(file_name)
count_files = len(next(os.walk(os.getcwd()))[2])
# os.walk yields 3-tuple (dirpath, dirnames, filenames) (Its a Generator)
for file in cwd_files:
if os.path.isfile(file):
ext = os.path.splitext(file) # Split the file into its name and extension
if (ext[1] in exts.get('Images')):
create_folder('Images')
shutil.move(file, './Images/')
elif (ext[1] in exts.get('Medias')):
create_folder('Media')
shutil.move(file, './Media/')
elif (ext[1] in exts.get('Docs')):
create_folder('Docs')
shutil.move(file, './Docs/')
elif (ext[1] in exts.get('Codes')):
create_folder('Codes')
shutil.move(file, './Codes/')
elif (ext[1] in exts.get('Archives')):
create_folder('Archives')
shutil.move(file, './Archives/')
elif (ext[1] in exts.get('Executables')):
create_folder('Exec')
shutil.move(file, './Exec/')
else:
create_folder('Others')
shutil.move(file, './Others/')
tmsg.showinfo("SUCCESS!", f"Your Directory Has Been Cleaned :)\n{count_files} file(s) Have Been Cleaned")
else:
tmsg.showerror("ERROR!", "Directory Not Found :(")
else:
tmsg.showerror("ERROR!", "Directory Not Found :(")
except OSError:
tmsg.showerror("Error!", "Directory Not Found :(")
root = Tk()
root.geometry('600x490')
root.minsize('600','490')
root.maxsize('600','490')
root.title("PY-CLEAN")
####### Background Image
bg_img = PhotoImage(file='bg.gif')
img_label = Label(root, image=bg_img)
img_label.place(relwidth=1, relheight=1)
####### Header
header_frm = Frame(root, background='#e8ca5f', relief=SUNKEN, bd=3)
header_frm.config(highlightthickness=0, highlightcolor='#c6d166', highlightbackground='#c6d166')
header_frm.pack(pady=7,fill=X)
header = Label(header_frm, text='PY-CLEAN', background='#e8ca5f', foreground='#FF1493', font="helvetica 19 bold", pady=3, padx=3)
header.pack(pady=4, fill=X)
###### Entry
path = StringVar()
side_label = Label(root, text='Enter Path To Clean ->', font="comicsansms 14 bold", padx=3, pady=4, background='#97b0cf', foreground='#bf391f', bd=3, relief=SUNKEN)
side_label.config(highlightthickness=2)
side_label.pack(anchor='w', padx=14, pady=45)
entry = Entry(root, textvariable=path, width=26, font="comicsansms 19 bold", background='#97b0cf', foreground='#343638', relief=SUNKEN, bd=2.5)
entry.config(highlightthickness=2.5, highlightcolor='#97b0cf', highlightbackground='#97b0cf')
entry.place(relx=0.35, rely=0.217)
### Selection Dialog Box, Clear Buttons
select_label = Label(root, text='Select Folder From Here ->', font="comicsansms 14 bold", padx=3, pady=4, background='#97b0cf', foreground='#bf391f', bd=3, relief=SUNKEN)
select_label.config(highlightthickness=2)
select_label.pack(anchor='w', padx=14, pady=50)
img = PhotoImage(file='folder.png')
folder_btn_frame = Frame(root, relief=SOLID, bd=4, background='#2160ad')
folder_btn_frame.place(relx=0.45, rely=0.45)
folder_btn = Button(folder_btn_frame, image=img, cursor='hand', command=select_folder)
folder_btn.config(highlightthickness=2, highlightcolor='#2160ad', highlightbackground='#2160ad')
folder_btn.pack()
btn_frame = Frame(root, relief=SUNKEN, bd=4, background='#3e4957')
btn_frame.place(relx=0.22, rely=0.82)
clean_btn = Button(btn_frame, text='Clean Now', font='comicsansms 22 bold', foreground='seagreen', cursor='hand', command=clean_dir)
clean_btn.config(highlightthickness=2, highlightcolor='#c4d64f', highlightbackground='#c4d64f')
clean_btn.pack()
clear_btn_frame = Frame(root, relief=SUNKEN, bd=4, background='#3e4957')
clear_btn_frame.place(relx=0.55, rely=0.82)
clear_btn = Button(clear_btn_frame, text='Clear Path', font='comicsansms 22 bold', foreground='red', cursor='hand', command=lambda : path.set(''))
clear_btn.config(highlightthickness=2, highlightcolor='#c4d64f', highlightbackground='#c4d64f')
clear_btn.pack()
root.mainloop()

View File

@ -148,6 +148,7 @@ So far, the following projects have been integrated to this repo:
|[YTS Torrents](yts_torrents)|[Mayank Nader](https://github.com/makkoncept)|
|[COVID visualiser (real-time) ](covdi_visualiser)|[Tushar Gupta](https://github.com/tushar5526)|
|[Random_Email_Generator](Random_Email_Generator)|[Shubham Garg](https://github.com/shub-garg)|
| [Py_Cleaner](Py_Cleaner) | [Abhishek Dobliyal](https://github.com/Abhishek-Dobliyal)
## How to use :