I have a program, json_formatter.exe
, that takes inputs of single filepaths in a command-line like environment and then formats the file it finds at the end of the path. I am trying to create a python script that runs the program and then feeds it large numbers of filepaths one at a time. While I managed to get json_formatter.exe
to run, I could not figure out how to input the filepaths into it. It takes input through command line parameters.
Here is what I have so far:
import argparse
import os
import subprocess
parser = argparse.ArgumentParser()
parser.add_argument('dir', action='store', nargs='+', help='Specify directories to be searched.')
args_dict = vars(parser.parse_args())
file_list = []
# Fill file_list with all .json files in the specified directory.
for file in args_dict['dir']:
for dirpath, dir_names, file_names in os.walk('.'):
if file in dirpath:
for root, dirn, filenames in os.walk(top=dirpath):
for filename in filenames:
if filename.endswith('.json'):
file_list.append(os.path.join(root, filename))
# Run json_formatter.exe
subprocess.run(args=f'start .\\tools\\format\\json_formatter.exe', shell=True)
for file in file_list:
os.system(file)