From cf444b3ca30133e6adaeab29b2e4043e0aa48681 Mon Sep 17 00:00:00 2001 From: ImAlpha Date: Wed, 13 Sep 2023 00:58:54 -0700 Subject: [PATCH] sorter improved for current working directory, needs line to be skipped --- .../DownloadSorter/DownloadSorter.py | 16 ---------- .../{TestFiles => }/pdf/hphpe250f_specs.pdf | Bin .../png/2023_07_28_batman-21837780.png | Bin .../DownloadSorter/py/DownloadSorter.py | 29 ++++++++++++++++++ Python_Scripts/GameSorter/GameSorter.py | 1 - 5 files changed, 29 insertions(+), 17 deletions(-) delete mode 100644 Python_Scripts/DownloadSorter/DownloadSorter.py rename Python_Scripts/DownloadSorter/{TestFiles => }/pdf/hphpe250f_specs.pdf (100%) rename Python_Scripts/DownloadSorter/{TestFiles => }/png/2023_07_28_batman-21837780.png (100%) create mode 100644 Python_Scripts/DownloadSorter/py/DownloadSorter.py diff --git a/Python_Scripts/DownloadSorter/DownloadSorter.py b/Python_Scripts/DownloadSorter/DownloadSorter.py deleted file mode 100644 index f6fa51a..0000000 --- a/Python_Scripts/DownloadSorter/DownloadSorter.py +++ /dev/null @@ -1,16 +0,0 @@ -import os -import shutil - -target_path = './TestFiles' -extensions = {item.split('.')[-1] for item in os.listdir(target_path) if os.path.isfile(os.path.join(target_path, item))} -# print(extensions) - -for ext in extensions: # Create a folder for extension types - if not os.path.exists(os.path.join(target_path, ext)): - os.mkdir(os.path.join(target_path, ext)) - -# Move the files into the folder -for item in os.listdir(target_path): - if os.path.isfile(os.path.join(target_path, item)): - file_extension = item.split('.')[-1] - shutil.move(os.path.join(target_path, item), os.path.join(target_path, file_extension, item)) \ No newline at end of file diff --git a/Python_Scripts/DownloadSorter/TestFiles/pdf/hphpe250f_specs.pdf b/Python_Scripts/DownloadSorter/pdf/hphpe250f_specs.pdf similarity index 100% rename from Python_Scripts/DownloadSorter/TestFiles/pdf/hphpe250f_specs.pdf rename to Python_Scripts/DownloadSorter/pdf/hphpe250f_specs.pdf diff --git a/Python_Scripts/DownloadSorter/TestFiles/png/2023_07_28_batman-21837780.png b/Python_Scripts/DownloadSorter/png/2023_07_28_batman-21837780.png similarity index 100% rename from Python_Scripts/DownloadSorter/TestFiles/png/2023_07_28_batman-21837780.png rename to Python_Scripts/DownloadSorter/png/2023_07_28_batman-21837780.png diff --git a/Python_Scripts/DownloadSorter/py/DownloadSorter.py b/Python_Scripts/DownloadSorter/py/DownloadSorter.py new file mode 100644 index 0000000..a73c59c --- /dev/null +++ b/Python_Scripts/DownloadSorter/py/DownloadSorter.py @@ -0,0 +1,29 @@ +import os +import shutil + +def create_dir(path, extensions): + for ext in extensions: + if not os.path.exists(os.path.join(path, ext)): + os.mkdir(os.path.join(path, ext)) + + +def move_files(target_path): + for file in os.listdir(target_path): + if os.path.isfile(os.path.join(target_path, file)): + file_extension = file.split('.')[-1] + shutil.move(os.path.join(target_path, file), os.path.join(target_path, file_extension, file)) + +def main(): + cwd = os.getcwd() + target_path = os.path.join(cwd) + extensions = {item.split('.')[-1] for item in os.listdir(target_path) if os.path.isfile(os.path.join(target_path, item))} + # print(extensions) + + # Create a folder for extension types + create_dir(target_path, extensions) + + # Move the files into the folder + move_files(target_path) + + +main() \ No newline at end of file diff --git a/Python_Scripts/GameSorter/GameSorter.py b/Python_Scripts/GameSorter/GameSorter.py index ebfa150..722f3e6 100644 --- a/Python_Scripts/GameSorter/GameSorter.py +++ b/Python_Scripts/GameSorter/GameSorter.py @@ -81,7 +81,6 @@ def run_command(command, path): os.chdir(cwd) - def main(source, target): # Get full folder path to avoid bugs in differing OS cwd = os.getcwd()