File size: 891 Bytes
3dc0e38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import os
import pandas as pd

def save_csv_files(folder_path):
    # 遍历文件夹及其子文件夹
    for root, dirs, files in os.walk(folder_path):
        for filename in files:
            # 检查文件是否为CSV文件
            if filename.endswith(".csv"):
                file_path = os.path.join(root, filename)
                try:
                    # 读取CSV文件
                    df = pd.read_csv(file_path)
                    # 重新保存CSV文件(覆盖原文件)
                    df.to_csv(file_path, index=False, encoding="utf-8-sig")
                    print(f"Re-saved file: {file_path}")
                except Exception as e:
                    print(f"Error processing file {file_path}: {e}")

# 指定要处理的文件夹路径
folder_path = input("请输入要处理的文件夹路径:")
save_csv_files(folder_path)