modified ExtensionName.py

master
piyx 5 years ago committed by piyx
parent 4ff6cc25df
commit cecaa94e1a

@ -6,9 +6,10 @@ def foldername(extension):
"exe" : "Software/Applications", "exe" : "Software/Applications",
"txt" : "Notes/Text", "txt" : "Notes/Text",
"pdf" : "PDFs", "pdf" : "PDFs",
"c" : "Code", "c" : "C programs",
"py" : "Code", "py" : "Python files",
"java": "Code", "java": "Java programs",
"cpp" : "Cpp programs",
"jpg" : "Images", "jpg" : "Images",
"png" : "Images", "png" : "Images",
"jpeg": "Images", "jpeg": "Images",
@ -17,4 +18,4 @@ def foldername(extension):
"mp4" : "Videos", "mp4" : "Videos",
"mkv" : "Videos", "mkv" : "Videos",
} }
return switcher.get(extension, "New Folder") #returns "New Folder" if not in dictionary return switcher.get(extension, "Extras") #returns "New Folder" if not in dictionary

@ -22,6 +22,10 @@ def organizeFiles():
print(key) print(key)
path = paths[input("\nEnter the folder to be organized:")] path = paths[input("\nEnter the folder to be organized:")]
if (path == "C:/"):
print("Cannot make changes to system folder")
return 0
list_files = os.listdir(path) list_files = os.listdir(path)
list_extension_names = set([os.path.splitext(file)[1].strip(".") for file in list_files]) list_extension_names = set([os.path.splitext(file)[1].strip(".") for file in list_files])
#os.path.splitext returns a tuple with file name and extension split #os.path.splitext returns a tuple with file name and extension split
@ -47,14 +51,15 @@ def organizeFiles():
if not os.path.exists(path + folder_name + "/" + file): if not os.path.exists(path + folder_name + "/" + file):
shutil.move(path + file, path + folder_name + "/" + file) shutil.move(path + file, path + folder_name + "/" + file)
print("Moved {} to {}".format(file, path + folder_name)) print("Moved {} to {}".format(file, path + folder_name))
return 0
if(choice == 1): if(choice == 1):
organizeFiles() organizeFiles()
elif(choice == 2): elif(choice == 2):
pass print("Backup feature not available yet")
elif(choice == 3): elif(choice == 3):
pass print("Feature to be added soon")
else: else:
print("\nInvalid Choice") print("\nInvalid Choice")

Loading…
Cancel
Save