import os
import pandas as pd
# 定义替换函数
def replace_quotes(file_path):
with open(file_path, 'r', encoding='utf-8') as f:
text = f.read()
new_text = text.replace("'", "\"")
with open(file_path, 'w', encoding='utf-8') as f:
f.write(new_text)
# 遍历指定文件夹及其子文件夹下所有txt文件
def traverse_files(folder_path):
for root, dirs, files in os.walk(folder_path):
for file in files:
if file.endswith('.txt'):
file_path = os.path.join(root, file)
try:
replace_quotes(file_path)
except:
print(f"发生错误:{file_path}")
if __name__ == '__main__':
folder_path = 'E:\dw1_xcredit_06'
traverse_files(folder_path)