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()