Skip to content

Instantly share code, notes, and snippets.

@crock
Last active March 5, 2019 00:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crock/9390e7603aea727dd808c47bf32113a6 to your computer and use it in GitHub Desktop.
Save crock/9390e7603aea727dd808c47bf32113a6 to your computer and use it in GitHub Desktop.
Simple Python script to run a specific EXE in a loop while providing different arguments per iteration (Requires Python 3.6+)
#!/usr/bin/env python3
# Copyright 2019
# Alex Crocker - croc122@gmail.com
import os
import platform
import subprocess
from argparse import ArgumentParser, RawDescriptionHelpFormatter
import glob
module_name = os.path.basename(__file__)
__version__ = "1.0.0"
def run(args):
if os.path.exists(os.path.join(os.getcwd(), args.dir)):
files = glob.glob(f"{args.dir}/**", recursive=args.recursive)
print(f"Found {len(files)} files")
for file in files:
filename, file_extension = os.path.splitext(file)
if os.path.isfile(filename):
if file_extension == ".txt":
output = f'deduped_{os.path.basename(file)}'
subprocess.check_call([
'App.Merge.exe',
f'o={output}',
f't={args.threads}',
f'c={args.cpu}',
file
])
if args.delete:
print(f"Removing file {os.path.basename(file)}")
os.remove(file)
def main():
version_string = f"{module_name}\n" + \
f"Version: {__version__}\n" + \
f"Python: {platform.python_version()}"
parser = ArgumentParser(formatter_class=RawDescriptionHelpFormatter,
description=f"{module_name} (Version {__version__})"
)
parser.add_argument("--version",
action="version", version=version_string,
help="Display version information and dependencies."
)
parser.add_argument("--dir", "-d", dest="dir",
help="Directory name"
)
parser.add_argument("--threads", "-t", dest="threads", default=20,
help="Number of processor threads"
)
parser.add_argument("--cpu", "-c", dest="cpu", default=3072,
help="Amount of RAM in MB"
)
parser.add_argument("--recursive", "-r", dest="recursive", default=False,
help="Find files in directory recursively (nested deeper than one level)"
)
parser.add_argument("--delete", "-D", dest="delete", default=False,
help="Delete the files after successful merge"
)
args = parser.parse_args()
run(args)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment