raku-26 / open20231115

0 stars 0 forks source link

nice #1

Open raku-26 opened 6 months ago

raku-26 commented 6 months ago

import os

def rename_files(directory):

遍历指定目录中的所有文件

for filename in os.listdir(directory):
    if filename.endswith("AAA"):
        # 构造原始文件的完整路径
        old_file = os.path.join(directory, filename)
        # 构造新的文件名,去掉末尾的"AAA"
        new_file = os.path.join(directory, filename[:-3])
        # 重命名文件
        os.rename(old_file, new_file)
        print(f"Renamed '{old_file}' to '{new_file}'")

调用函数,输入你的文件夹路径

directory_path = "your_directory_path_here" rename_files(directory_path)

raku-26 commented 6 months ago

import csv

def remove_first_line(input_filename, output_filename): with open(input_filename, mode='r', newline='') as file: reader = csv.reader(file) next(reader) # 跳过第一行(标题行)

    with open(output_filename, mode='w', newline='') as outfile:
        writer = csv.writer(outfile)
        # 写入剩余行
        for row in reader:
            writer.writerow(row)

使用示例

input_filename = 'input.csv' output_filename = 'output.csv' remove_first_line(input_filename, output_filename)