Created
November 27, 2021 11:01
-
-
Save harendra21/1c936b1ac2462cfc960134f5c2b24f05 to your computer and use it in GitHub Desktop.
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
import os | |
import shutil | |
os.chdir("E:\downloads") | |
#print(os.getcwd()) | |
#check number of files in directory | |
files = os.listdir() | |
#list of extension (You can add more if you want) | |
extentions = { | |
"images": [".jpg", ".png", ".jpeg", ".gif"], | |
"videos": [".mp4", ".mkv"], | |
"musics": [".mp3", ".wav"], | |
"zip": [".zip", ".tgz", ".rar", ".tar"], | |
"documents": [".pdf", ".docx", ".csv", ".xlsx", ".pptx", ".doc", ".ppt", ".xls"], | |
"setup": [".msi", ".exe"], | |
"programs": [".py", ".c", ".cpp", ".php", ".C", ".CPP"], | |
"design": [".xd", ".psd"] | |
} | |
#sort to specific folder depend on extenstions | |
def sorting(file): | |
keys = list(extentions.keys()) | |
for key in keys: | |
for ext in extentions[key]: | |
# print(ext) | |
if file.endswith(ext): | |
return key | |
#iterat through each file | |
for file in files: | |
dist = sorting(file) | |
if dist: | |
try: | |
shutil.move(file, "../download-sorting/" + dist) | |
except: | |
print(file + " is already exist") | |
else: | |
try: | |
shutil.move(file, "../download-sorting/others") | |
except: | |
print(file + " is already exist") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment