doSpgen_all.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import os
  2. import glob
  3. import subprocess
  4. # 定义文件路径
  5. relative_file_path = r'bin\Debug\spgen.exe'
  6. def find_xml_files(directory):
  7. """
  8. 扫描指定目录及其所有子目录下的.xml文件,并返回这些文件的路径列表。
  9. :param directory: 要扫描的目录路径
  10. :return: 包含.xml文件路径的列表
  11. """
  12. # 使用**表示递归地匹配所有子目录
  13. xml_file_paths = glob.glob(os.path.join(directory, '**', '*.xml'), recursive=True)
  14. return xml_file_paths
  15. # 指定要扫描的目录
  16. module_directory = r'..\..\Module'
  17. if __name__ == '__main__':
  18. # 获取当前工作目录
  19. current_working_directory = os.getcwd()
  20. # 构建绝对路径
  21. absolute_file_path = os.path.join(current_working_directory, relative_file_path)
  22. # 检查文件是否存在
  23. if os.path.exists(absolute_file_path):
  24. print(f"文件 '{absolute_file_path}' 存在。")
  25. else:
  26. print(f"文件 '{absolute_file_path}' 不存在。")
  27. exit()
  28. # 调用函数并打印结果
  29. xml_files_list = find_xml_files(module_directory)
  30. for file_path in xml_files_list:
  31. dstcmd = absolute_file_path + ' ' +file_path
  32. print(dstcmd)
  33. subprocess.run(dstcmd, shell=True, capture_output=True, text=True)