问题描述
我有一个程序json_formatter.exe
,它在类似命令行的环境中接受单个文件路径的输入,然后格式化它在路径末尾找到的文件。我正在尝试创建一个运行程序的python脚本,然后一次提供大量的文件路径。尽管设法使json_formatter.exe
运行,但我仍无法弄清楚如何在其中输入文件路径。它通过命令行参数进行输入。
这是我到目前为止所拥有的:
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)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)