|
|
@ -12,30 +12,31 @@ EXT_NAME = "ext.py"
|
|
|
|
def organize_files(drive):
|
|
|
|
def organize_files(drive):
|
|
|
|
# check os
|
|
|
|
# check os
|
|
|
|
operating_system = platform.system()
|
|
|
|
operating_system = platform.system()
|
|
|
|
if operating_system == 'Darwin': # Mac
|
|
|
|
if operating_system == "Windows": # Windows
|
|
|
|
drive = os.path.expanduser(drive)
|
|
|
|
drive = drive + "\\"
|
|
|
|
if not os.path.exists(drive):
|
|
|
|
if not os.path.exists(drive):
|
|
|
|
print(f"ERROR! {drive} is not a valid location")
|
|
|
|
print(f"ERROR! {drive} is not a valid location")
|
|
|
|
return
|
|
|
|
return
|
|
|
|
files = os.listdir(drive)
|
|
|
|
files = os.listdir(drive)
|
|
|
|
extns = {os.path.splitext(file)[1].strip('.') for file in files}
|
|
|
|
extns = {os.path.splitext(file)[1].strip(".") for file in files}
|
|
|
|
|
|
|
|
|
|
|
|
# Create Folders
|
|
|
|
# Create Folders
|
|
|
|
for ext in extns:
|
|
|
|
for ext in extns:
|
|
|
|
folder = foldername(ext)
|
|
|
|
folder = foldername(ext)
|
|
|
|
if folder and not os.path.exists(os.path.join(drive, folder)):
|
|
|
|
if folder and not os.path.exists(drive + folder):
|
|
|
|
os.makedirs(os.path.join(drive, folder))
|
|
|
|
os.makedirs(drive + folder)
|
|
|
|
|
|
|
|
|
|
|
|
# Move Files To Folders
|
|
|
|
# Move Files To Folders
|
|
|
|
for file in files:
|
|
|
|
for file in files:
|
|
|
|
if file in [FILE_NAME, EXT_NAME]:
|
|
|
|
if file in [FILE_NAME, EXT_NAME]:
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
ext = os.path.splitext(file)[1].strip('.')
|
|
|
|
ext = os.path.splitext(file)[1].strip(".")
|
|
|
|
folder = foldername(ext)
|
|
|
|
folder = foldername(ext)
|
|
|
|
if not folder:
|
|
|
|
if not folder:
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
|
|
src = os.path.join(drive, file)
|
|
|
|
src = drive + file
|
|
|
|
dest = os.path.join(drive, folder, file)
|
|
|
|
dest = drive + folder + "/" + file
|
|
|
|
|
|
|
|
|
|
|
|
if not os.path.exists(dest):
|
|
|
|
if not os.path.exists(dest):
|
|
|
|
shutil.move(src, dest)
|
|
|
|
shutil.move(src, dest)
|
|
|
@ -43,31 +44,30 @@ def organize_files(drive):
|
|
|
|
|
|
|
|
|
|
|
|
print(f"\nSUCCESS! All files organized in {drive}")
|
|
|
|
print(f"\nSUCCESS! All files organized in {drive}")
|
|
|
|
|
|
|
|
|
|
|
|
elif operating_system == 'Windows': # Windows
|
|
|
|
elif operating_system == "Darwin": # Mac
|
|
|
|
drive = drive + '\\'
|
|
|
|
drive = os.path.expanduser(drive)
|
|
|
|
if not os.path.exists(drive):
|
|
|
|
if not os.path.exists(drive):
|
|
|
|
print(f"ERROR! {drive} is not a valid location")
|
|
|
|
print(f"ERROR! {drive} is not a valid location")
|
|
|
|
return
|
|
|
|
return
|
|
|
|
files = os.listdir(drive)
|
|
|
|
files = os.listdir(drive)
|
|
|
|
extns = {os.path.splitext(file)[1].strip('.') for file in files}
|
|
|
|
extns = {os.path.splitext(file)[1].strip(".") for file in files}
|
|
|
|
|
|
|
|
|
|
|
|
# Create Folders
|
|
|
|
# Create Folders
|
|
|
|
for ext in extns:
|
|
|
|
for ext in extns:
|
|
|
|
folder = foldername(ext)
|
|
|
|
folder = foldername(ext)
|
|
|
|
if folder and not os.path.exists(drive + folder):
|
|
|
|
if folder and not os.path.exists(os.path.join(drive, folder)):
|
|
|
|
os.makedirs(drive + folder)
|
|
|
|
os.makedirs(os.path.join(drive, folder))
|
|
|
|
|
|
|
|
|
|
|
|
# Move Files To Folders
|
|
|
|
# Move Files To Folders
|
|
|
|
for file in files:
|
|
|
|
for file in files:
|
|
|
|
if file in [FILE_NAME, EXT_NAME]:
|
|
|
|
if file in [FILE_NAME, EXT_NAME]:
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
ext = os.path.splitext(file)[1].strip('.')
|
|
|
|
ext = os.path.splitext(file)[1].strip(".")
|
|
|
|
folder = foldername(ext)
|
|
|
|
folder = foldername(ext)
|
|
|
|
if not folder:
|
|
|
|
if not folder:
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
|
|
src = drive + file
|
|
|
|
src = os.path.join(drive, file)
|
|
|
|
dest = drive + folder + '/' + file
|
|
|
|
dest = os.path.join(drive, folder, file)
|
|
|
|
|
|
|
|
|
|
|
|
if not os.path.exists(dest):
|
|
|
|
if not os.path.exists(dest):
|
|
|
|
shutil.move(src, dest)
|
|
|
|
shutil.move(src, dest)
|
|
|
@ -75,7 +75,7 @@ def organize_files(drive):
|
|
|
|
|
|
|
|
|
|
|
|
print(f"\nSUCCESS! All files organized in {drive}")
|
|
|
|
print(f"\nSUCCESS! All files organized in {drive}")
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
print(f'{operating_system} not currently supported')
|
|
|
|
print(f"{operating_system} not currently supported")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
if __name__ == "__main__":
|
|
|
|