我希望脚本排除模板文件,排除文件名中没有10个字符串的任何文件,然后查找文件名中带有+的文件,然后在每个文件中删除+
无法弄清楚如何过滤文件名中包含+的文件
import os
directory_path=os.path.dirname(os.path.abspath(__file__))
template_file_name='? exchange symbol buyorsell positionSide longorshort positionOperator value= closeorder +-'
template_arr = template_file_name.split()
template_file_content = open(directory_path + "/" + template_file_name, "r").read()
for root, dirs, files in os.walk(directory_path):
file_info = []
for file in files:
destination_filename = os.path.join(file)
#excludes template file
if(destination_filename!=template_file_name):
destination_filename_arr = destination_filename.split()
if(len(destination_filename_arr) != 10):
#skips files that don't have 10 strings in filename
print("Skipping this file: " + destination_filename)
continue;
#need help filtering files that contain + in filename
if(destination_filename_arr contains "+"):
continue;
#open files and replace strings
with open(os.path.join(directory_path, file), 'r+') as destination_filename_content:
for x in range(10):
destination_filename_content = destination_filename_content.replace("+", " ")
destination_file = open(directory_path + "/" + destination_filename,"w")
destination_file.write(destination_filename_content)