import os import shutil def find_and_copy_files(input_folder, output_folder): # 确保输出文件夹存在 os.makedirs(output_folder, exist_ok=True) # 定义支持的文件格式 supported_formats = ('.pdf', '.doc', '.docx') # 遍历输入文件夹 for root, dirs, files in os.walk(input_folder): for file in files: # 检查文件名是否包含“招标”或“竞争性”并且文件格式正确 if ('响应' not in file and '投标' not in file) and \ ('竞争性' in file or '招标文件' in file or '磋商' in file) and \ file.endswith(supported_formats): # 构造完整的文件路径 file_path = os.path.join(root, file) # 构造输出路径 output_path = os.path.join(output_folder, file) # 检查输出路径是否存在同名文件 unique_path = output_path count = 1 while os.path.exists(unique_path): # 文件名前加上编号,格式如:filename(1).ext base, extension = os.path.splitext(output_path) unique_path = f"{base}({count}){extension}" count += 1 # 复制文件到唯一的路径 shutil.copy2(file_path, unique_path) print(f"Copied '{file}' to '{unique_path}'.") # 使用示例 input_folder = 'Z:\\货物类tb\\投标项目资料' # 输入文件夹路径 output_folder = 'C:\\Users\\Administrator\\Desktop\\货物标\\zbfiles' # 输出文件夹路径 find_and_copy_files(input_folder, output_folder)