diff options
author | Reinier van der Leer <pwuts@agpt.co> | 2024-01-29 18:29:24 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-29 18:29:24 +0100 |
commit | 575be818ca1f7c644e2adf94c584772547141f55 (patch) | |
tree | abb052ae787b1107c9dff8fb4d86ee84842d515d /benchmark/agbenchmark/challenges/verticals/code/3_file_organizer/artifacts_out/organize_files.py | |
parent | Update ossf-scorecard.yml (diff) | |
parent | fix(agent/json_utils): Make `extract_dict_from_response` more robust (diff) | |
download | Auto-GPT-security/analysis-workflows-sandbox.tar.gz Auto-GPT-security/analysis-workflows-sandbox.tar.bz2 Auto-GPT-security/analysis-workflows-sandbox.zip |
Merge branch 'master' into security/analysis-workflows-sandboxsecurity/analysis-workflows-sandbox
Diffstat (limited to 'benchmark/agbenchmark/challenges/verticals/code/3_file_organizer/artifacts_out/organize_files.py')
-rw-r--r-- | benchmark/agbenchmark/challenges/verticals/code/3_file_organizer/artifacts_out/organize_files.py | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/benchmark/agbenchmark/challenges/verticals/code/3_file_organizer/artifacts_out/organize_files.py b/benchmark/agbenchmark/challenges/verticals/code/3_file_organizer/artifacts_out/organize_files.py new file mode 100644 index 000000000..dcbc77573 --- /dev/null +++ b/benchmark/agbenchmark/challenges/verticals/code/3_file_organizer/artifacts_out/organize_files.py @@ -0,0 +1,48 @@ +import argparse +import os +import shutil + + +def organize_files(directory_path): + # Define file type groups + file_types = { + "images": [".png", ".jpg", ".jpeg"], + "documents": [".pdf", ".docx", ".txt"], + "audio": [".mp3", ".wav", ".flac"], + } + + # Create the folders if they don't exist + for folder_name in file_types.keys(): + folder_path = os.path.join(directory_path, folder_name) + if not os.path.exists(folder_path): + os.makedirs(folder_path) + + # Traverse through all files and folders in the specified directory + for foldername, subfolders, filenames in os.walk(directory_path): + for filename in filenames: + # Get file extension + _, file_extension = os.path.splitext(filename) + + # Move files to corresponding folders + for folder_name, extensions in file_types.items(): + if file_extension in extensions: + old_path = os.path.join(foldername, filename) + new_path = os.path.join(directory_path, folder_name, filename) + if old_path != new_path: + shutil.move(old_path, new_path) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser( + description="Organize files in a directory based on their file types" + ) + parser.add_argument( + "--directory_path", + type=str, + required=True, + help="The path of the directory to be organized", + ) + + args = parser.parse_args() + + organize_files(args.directory_path) |