You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
2.4 KiB
83 lines
2.4 KiB
5 years ago
|
import os
|
||
|
import shutil
|
||
4 years ago
|
import ext
|
||
5 years ago
|
|
||
|
FileName = "FileOrganizeAutomation.py"
|
||
|
ExtensionModule = "ExtensionName.py"
|
||
|
|
||
|
paths = {
|
||
4 years ago
|
"Downloads": "Downloads/",
|
||
|
"Desktop": "Desktop/",
|
||
|
"Documents": "Documents/",
|
||
|
"C Drive": "C:/",
|
||
|
"D Drive": "D:/"
|
||
5 years ago
|
}
|
||
|
|
||
4 years ago
|
|
||
5 years ago
|
def organizeFiles():
|
||
|
print("\n\nFolders...\n")
|
||
|
for key in paths.keys():
|
||
|
print(key)
|
||
|
|
||
5 years ago
|
print("\n1-->Choose Path from above\n2-->Set custom path\n")
|
||
|
choice = int(input("Enter choice:"))
|
||
|
if choice == 1:
|
||
|
path = paths[input("\nEnter the folder to be organized:")]
|
||
4 years ago
|
|
||
5 years ago
|
elif choice == 2:
|
||
|
path = input("Enter custom path:") + '/'
|
||
|
print("\n")
|
||
|
else:
|
||
|
print("Invalid Choice!")
|
||
|
return 0
|
||
5 years ago
|
|
||
|
if (path == "C:/"):
|
||
|
print("Cannot make changes to system folder")
|
||
|
return 0
|
||
5 years ago
|
list_files = os.listdir(path)
|
||
4 years ago
|
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
|
||
5 years ago
|
#Eg: Filename = Hello.txt
|
||
4 years ago
|
# -----> os.path.splitext(file) returns ("Hello", ".txt")
|
||
5 years ago
|
|
||
4 years ago
|
# Create New Folders
|
||
5 years ago
|
for extension in list_extension_names:
|
||
|
folder_name = ext.foldername(extension)
|
||
4 years ago
|
if(folder_name == None): # Folder_name = None --> Its a folder
|
||
|
continue # No need to make new folder
|
||
5 years ago
|
if not os.path.exists(path + folder_name):
|
||
|
os.makedirs(path + folder_name)
|
||
4 years ago
|
|
||
|
# Move Files To Respective Folder
|
||
5 years ago
|
for file in list_files:
|
||
|
if(file == FileName or file == ExtensionModule):
|
||
|
continue
|
||
|
file_extension = os.path.splitext(file)[1].strip(".")
|
||
|
folder_name = ext.foldername(file_extension)
|
||
|
if(folder_name == None):
|
||
|
continue
|
||
|
if not os.path.exists(path + folder_name + "/" + file):
|
||
|
shutil.move(path + file, path + folder_name + "/" + file)
|
||
|
print("Moved {} to {}".format(file, path + folder_name))
|
||
5 years ago
|
return 0
|
||
5 years ago
|
|
||
|
|
||
5 years ago
|
def main():
|
||
|
print("\n\n1:Organize Files\n2:Backup To Drive\n3:Rename Unordered Files")
|
||
|
choice = int(input("\nEnter choice:"))
|
||
|
|
||
|
if(choice == 1):
|
||
|
organizeFiles()
|
||
|
elif(choice == 2):
|
||
|
print("Backup feature not available yet")
|
||
|
elif(choice == 3):
|
||
|
print("Feature to be added soon")
|
||
|
else:
|
||
|
print("\nInvalid Choice")
|
||
|
|
||
|
|
||
|
if __name__ == "__main__":
|
||
4 years ago
|
print(os.listdir("C:/Users/ctrla/Downloads/"))
|
||
5 years ago
|
main()
|