From d2a4ba3fce053889bb09334c0b3a497b1f5ec945 Mon Sep 17 00:00:00 2001 From: Roshan Kumar Date: Mon, 7 Dec 2020 11:18:49 +0530 Subject: [PATCH 1/2] initial commit --- Automations/messy-folder-cleaner/main.py | 85 ++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 Automations/messy-folder-cleaner/main.py diff --git a/Automations/messy-folder-cleaner/main.py b/Automations/messy-folder-cleaner/main.py new file mode 100644 index 0000000..346a5f8 --- /dev/null +++ b/Automations/messy-folder-cleaner/main.py @@ -0,0 +1,85 @@ +import os +import shutil # for moving and copyinf items + +def makefolder(filelist): + # make folders according to file extensions + extlst= [] # stores folder name accordinf to extinction + for items in filelist: + if items.endswith(".txt"): + extlst.append("Text_File") + + elif items.endswith(".mp3"): + extlst.append("Music") + + elif items.endswith(".png") or items.endswith(".PNG") or items.endswith(".jpeg") or items.endswith(".jpg"): + extlst.append("Pictures") + + elif items.endswith(".mp4") or items.endswith(".mkv"): + extlst.append("Videos") + + elif items.endswith(".pdf") or items.endswith(".docs") or items.endswith(".xlxs"): + extlst.append("Documents") + + elif items.endswith(".py"): + extlst.append("Python") + + elif items.endswith(".js"): + extlst.append("Javascript") + extlst = list(dict.fromkeys(extlst)) # removes duplicate items from the list + for items in extlst: + try: + os.mkdir(items) + except FileExistsError: + continue + +def organise(filelist): + # moves files in folders accordind to their extentions + for items in filelist: + if items.endswith(".txt"): + loc = os.getcwd() + "\Text_Files" + shutil.move(items, loc) + + elif items.endswith(".mp3"): + loc = os.getcwd() + "\Music" + shutil.move(items, loc) + + + elif items.endswith(".png") or items.endswith(".jpeg") or items.endswith(".jpg"): + loc = os.getcwd() + "\Pictures" + shutil.move(items, loc) + + + elif items.endswith(".mp4") or items.endswith(".mkv"): + loc = os.getcwd() + "\Videos" + shutil.move(items, loc) + + + elif items.endswith(".pdf") or items.endswith(".docx") or items.endswith(".xlxs"): + loc = os.getcwd() + "\Documents" + shutil.move(items, loc) + + + # elif items.endswith(".py"): + # loc = os.getcwd() + "\Python" + # shutil.move(items, loc) + + + elif items.endswith(".js"): + loc = os.getcwd() + "\Javascript" + shutil.move(items, loc) + +if __name__=='__main__': + filelist = [] + if len(os.listdir())==1: + print("Folder is empty") + inp = input("Press any key to continue") + exit() + else: + for folders, subfolder, files in os.walk(os.getcwd()): + for items in files: + filelist.append(items) + print(filelist) + makefolder(filelist) + organise(filelist) + print("Done!!!") + inp = input("Press any key to continue......") \ No newline at end of file From df42fd3a82e2e9b455c3b7897732a46b0e4c2da1 Mon Sep 17 00:00:00 2001 From: Roshan Kumar Date: Tue, 8 Dec 2020 00:18:26 +0530 Subject: [PATCH 2/2] Added README.md --- Automations/messy-folder-cleaner/README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Automations/messy-folder-cleaner/README.md diff --git a/Automations/messy-folder-cleaner/README.md b/Automations/messy-folder-cleaner/README.md new file mode 100644 index 0000000..d78dfba --- /dev/null +++ b/Automations/messy-folder-cleaner/README.md @@ -0,0 +1,10 @@ +# Messy Folder Cleaner + A program that would clean up a messy folder in just one click. + Like if a folder contains a bunch of images, songs, pdf, word documents, videos, etc it will create corresponding folders for images, songs, and all other stuff and move those in that folder. + +### How to use this program ? 💻 +- Just copy the **main.py** to the folder in which you want a clean up +- Run this script +- Thats it. Done + +