Hi I am new to python and I made this simple program to sort out my downloads folder. When I run this program when i have decent number of files in download folder, it takes roughly around 10 to 15 seconds.
I heard python is slower with respect to C.
Best way to make this code more efficient without parallel threads?
Also, Best way to make it faster with parallel running threads?
My next plan is to use python to make a GUI for a desktop dashboard where I can have this code as runnable icon. How can I achieve that... any ideas would be greatly appreciated. Thanks for the help.
import shutil
import os, time
start = time.time()
print("Sorting Downlaods Folder...")
download_folder = "C:/Users/muham/Downloads"
images = "C:/Users/muham/Pictures"
documents = "C:/Users/muham/Documents"
docs = ["docx", ".txt", ".doc"]
imgs = [".png", ".jpg", "jpeg"]
prgrms = [".exe", ".php", ".c", "java", ".msi"]
for file in os.listdir(download_folder):
if file[-4:] in docs:
shutil.move(download_folder + '/' + file, documents + '/Docs/' + file)
elif file[-4:] == "xlsx" or file[-4:] == ".csv":
shutil.move(download_folder + '/' + file, documents + '/Excel/' + file)
elif file[-4:] == ".pdf" or file[-4:] == ".ppt" or file[-4:] == ".pptx":
shutil.move(download_folder + '/' + file, documents + '/PDFs/' + file)
elif file[-4:] in imgs:
shutil.move(download_folder + '/' + file, images + '/' + file)
elif file[-4:] in prgrms or file[-2:] == ".c":
shutil.move(download_folder + '/' + file, "D:/programs/" + file)
else:
shutil.move(download_folder + '/' + file, "D:/zips/" + file)
print("Download folder sorted")
end = time.time()
print("Time taken:" , end - start)