Created
October 23, 2020 02:26
-
-
Save mertzjames/fd1a7fd65bc4bbc291bd6265a7b0f708 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pathlib | |
| import argparse | |
| def find_all_files(path: pathlib.Path, extension: str): | |
| found_files = [] | |
| for f in path.glob(f"**/*{extension}"): | |
| found_files.append(f) | |
| return found_files | |
| def remove_files(file_list, dummy_action): | |
| if dummy_action: | |
| print("Iterating over files to be removed. NO ACTION WILL BE TAKEN") | |
| else: | |
| print("Iterating over files to be removed. THESE FILES WILL BE REMOVED!") | |
| for f in file_list: | |
| print(f"Removing file: {f}") | |
| if not dummy_action: | |
| f.unlink() | |
| if __name__ == '__main__': | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument('folder_location') | |
| parser.add_argument('--extension', '-e', default='.mp3') | |
| parser.add_argument('--dummy', '-d', action='store_true') | |
| args = parser.parse_args() | |
| path = pathlib.Path(args.folder_location) | |
| if not path.is_dir() or not path.exists(): | |
| raise ValueError(f"{path} is not a valid dirctory") | |
| files = find_all_files(path, args.extension) | |
| remove_files(files, args.dummy) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment