29 lines
1.1 KiB
Python
29 lines
1.1 KiB
Python
import os
|
|
import pandas as pd
|
|
|
|
def convert_csv_to_xlsx(directory):
|
|
# 遍历目录及其子目录
|
|
for root, dirs, files in os.walk(directory):
|
|
for file in files:
|
|
# if file.endswith('data.csv'):
|
|
# csv_file_path = os.path.join(root, file)
|
|
# xlsx_file_path = os.path.splitext(csv_file_path)[0] + '.xlsx'
|
|
#
|
|
# # 读取CSV文件并转换为XLSX
|
|
# df = pd.read_csv(csv_file_path)
|
|
# df.to_excel(xlsx_file_path, index=False)
|
|
#
|
|
# # 删除原始的CSV文件
|
|
# os.remove(csv_file_path)
|
|
# print(f"Converted and deleted: {csv_file_path}")
|
|
|
|
# 删除所有文件名不等于data.xlsx的文件
|
|
if not file.endswith('data.xlsx'):
|
|
file_path = os.path.join(root, file)
|
|
os.remove(file_path)
|
|
print(f"Deleted: {file_path}")
|
|
|
|
if __name__ == "__main__":
|
|
# 指定要处理的目录
|
|
directory = 'downloaded_files'
|
|
convert_csv_to_xlsx(directory) |