Created
September 13, 2021 07:29
-
-
Save Dhravya/badad4fd772ee06336248c9f56bf202d to your computer and use it in GitHub Desktop.
Basic file organiser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from logging import exception | |
import os | |
import shutil | |
import time | |
path = "C:/Users/dhrav/Downloads/Organiser" | |
files = os.listdir(path) | |
listOfDirectories = { | |
'Picture_Folder': ['jpeg', 'jpg', 'gif', 'png'], | |
'Video_Folder': ['wmv', 'mov', 'mp4','mpg', 'mpeg', 'mkv'], | |
'Zip_Folder': ['iso', 'tar', 'gz', 'rz', '7z','dmg','rar', 'zip', '.exe'], | |
'Music_Folder': ['mp3', 'msv','wav', 'wma'], | |
'PDF_Folder': ['pdf'], | |
'Minecraft_Folder' : ['mcpack', 'mcworld'], | |
'python_Folder' : ['py']} | |
def Organiser(file): | |
if extension in listOfDirectories['Picture_Folder']: | |
shutil.move(path+"/"+file,'C:/Users/dhrav/Pictures') | |
elif extension in listOfDirectories['PDF_Folder']: | |
shutil.move(path+"/"+file,'C:/Users/dhrav/Documents/PDFs') | |
elif extension in listOfDirectories['Zip_Folder']: | |
shutil.move(path+"/"+file,'C:/Users/dhrav/Downloads/Installers') | |
elif extension in listOfDirectories['Video_Folder']: | |
shutil.move(path+"/"+file,'C:/Users/dhrav/Documents/Videos') | |
elif extension in listOfDirectories['Music_Folder']: | |
shutil.move(path+"/"+file,'C:/Users/dhrav/Documents/Music') | |
elif extension in listOfDirectories['Minecraft_Folder']: | |
shutil.move(path+"/"+file,'C:/Users/dhrav/Documents/Minecraft') | |
elif extension in listOfDirectories['python_Folder']: | |
shutil.move(path+"/"+file,'C:/Users/dhrav/Documents/Python Projects') | |
else: | |
shutil.move(path+"/"+file,'C:/Users/dhrav/Documents/Other files') | |
n = 0 | |
while True: | |
if len(os.listdir(path))>0: | |
for file in files: | |
filename, extension = os.path.splitext(file) | |
extension = extension[1:] | |
print(extension) | |
try: | |
Organiser(file) | |
except: | |
os.rename(path+'/'+file,path+'/'+filename+'1.'+extension) | |
file = filename+"1."+extension | |
Organiser(file) | |
n +=1 | |
print("File~" + str(n) + "moved") | |
else: | |
print ('There are no Files to organise! Waiting for 60s') | |
time.sleep(60) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment