import os
import re
def remove_characters_from_file(file_path):
with open(file_path, 'r', encoding='utf-8') as file:
content = file.read()
# 删除所有中英文括号及数字
new_content = re.sub(r'[\(\)\[\]\{\}()【】0-9]', '', content)
with open(file_path, 'w', encoding='utf-8') as file:
file.write(new_content)
def process_directory(directory):
for root, dirs, files in os.walk(directory):
for file in files:
if file.endswith('.txt'):
file_path = os.path.join(root, file)
remove_characters_from_file(file_path)
print(f'Processed: {file_path}')
if __name__ == "__main__":
directory = input("请输入文件夹路径: ")
process_directory(directory)
print("处理完成。")