Last active
May 18, 2022 21:50
-
-
Save brandonlou/d8112c8c55acf75c533ff2e5be551e29 to your computer and use it in GitHub Desktop.
Keep only exe files in a directory
This file contains 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 argparse | |
import filetype | |
import os | |
def main(): | |
parser = argparse.ArgumentParser(description='Keep all exe files in a directory and remove the rest') | |
parser.add_argument('directory') | |
args = parser.parse_args() | |
directory = args.directory | |
for filename in os.listdir(directory): | |
filepath = f'{directory}/{filename}' | |
kind = filetype.guess(filepath) | |
if kind is None or kind.extension != 'exe': | |
os.remove(filepath) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment