123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- import os
- import glob
- import subprocess
- # 定义文件路径
- relative_file_path = r'bin\Debug\spgen.exe'
- def find_xml_files(directory):
- """
- 扫描指定目录及其所有子目录下的.xml文件,并返回这些文件的路径列表。
-
- :param directory: 要扫描的目录路径
- :return: 包含.xml文件路径的列表
- """
- # 使用**表示递归地匹配所有子目录
- xml_file_paths = glob.glob(os.path.join(directory, '**', '*.xml'), recursive=True)
- return xml_file_paths
- # 指定要扫描的目录
- module_directory = r'..\..\Module'
- if __name__ == '__main__':
- # 获取当前工作目录
- current_working_directory = os.getcwd()
- # 构建绝对路径
- absolute_file_path = os.path.join(current_working_directory, relative_file_path)
- # 检查文件是否存在
- if os.path.exists(absolute_file_path):
- print(f"文件 '{absolute_file_path}' 存在。")
- else:
- print(f"文件 '{absolute_file_path}' 不存在。")
- exit()
- # 调用函数并打印结果
- xml_files_list = find_xml_files(module_directory)
- for file_path in xml_files_list:
- dstcmd = absolute_file_path + ' ' +file_path
- print(dstcmd)
- subprocess.run(dstcmd, shell=True, capture_output=True, text=True)
|