fixed path joins

master
piyx 4 years ago committed by piyx
parent 4fa28b0f4b
commit 27abd4fad8

Binary file not shown.

@ -12,7 +12,7 @@ EXT_NAME = "ext.py"
def organize_files(path): def organize_files(path):
operating_system = platform.system() operating_system = platform.system()
if operating_system == "Windows": # Windows if operating_system == "Windows": # Windows
path = path + "\\" pass
elif operating_system == "Darwin": # Mac elif operating_system == "Darwin": # Mac
path = os.path.expanduser(path) path = os.path.expanduser(path)
else: else:
@ -26,21 +26,23 @@ def organize_files(path):
# Create Folders # Create Folders
for ext in extns: for ext in extns:
folder = foldername(ext) folder = foldername(ext) or ''
if folder and not os.path.exists(path + folder): new = os.path.join(path, folder)
os.makedirs(path + folder) if folder and not os.path.exists(new):
os.makedirs(new)
# 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 = path + file src = os.path.join(path, file)
dest = path + folder + "/" + file dest = os.path.join(path, folder, file)
if not os.path.exists(dest): if not os.path.exists(dest):
shutil.move(src, dest) shutil.move(src, dest)
@ -49,6 +51,7 @@ def organize_files(path):
print(f"\nSUCCESS! All files organized in {path}") print(f"\nSUCCESS! All files organized in {path}")
if __name__ == "__main__":
try: try:
location = sys.argv[1] location = sys.argv[1]
organize_files(location) organize_files(location)

Loading…
Cancel
Save