Skip to content

Commit

Permalink
Merge pull request #22 from Roshaen/master
Browse files Browse the repository at this point in the history
Messy folder cleaner
  • Loading branch information
Arsenic-ATG committed Dec 8, 2020
2 parents 806c2f7 + df42fd3 commit dfa98c2
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Automations/messy-folder-cleaner/README.md
Original file line number Diff line number Diff line change
@@ -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


85 changes: 85 additions & 0 deletions Automations/messy-folder-cleaner/main.py
Original file line number Diff line number Diff line change
@@ -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......")

0 comments on commit dfa98c2

Please sign in to comment.