2023年11月

import os
import codecs


def ansi_to_utf8(folder_path):
    for filename in os.listdir(folder_path):
        file_path = os.path.join(folder_path, filename)
        if os.path.isfile(file_path):
            with codecs.open(file_path, 'r', encoding='ansi') as file:
                content = file.read()
            with codecs.open(file_path, 'w', encoding='utf-8') as file:
                file.write(content)


# 调用示例
folder_path = 'name'  # 替换为你的文件夹路径
ansi_to_utf8(folder_path)

import os


# 读取文件夹内文件名称的函数
def get_all_filenames(folder_path):
    filenames = []
    for filename in os.listdir(folder_path):
        if os.path.isfile(os.path.join(folder_path, filename)):
            filenames.append(filename)
    return filenames


folder_path = "name"  # 同目录的文件夹名
txt_name = "whiteRaf.txt"  # 同目录输出文件名

# 引用的目录,根据实际自行填写
raf_a = '<a href="/downloads/mp3/MIYAZAKI/'
# html格式相关信息
raf_b = '" style="text-decoration: none;font-family: Arial, Helvetica, sans-serif;">'
# 结尾和换行
raf_c = '</a>\n'

# 调用函数
all_filenames = get_all_filenames(folder_path)

# 写入文件
with open(txt_name, 'w') as file_object:
    for filename in all_filenames:
        file_object.write(raf_a + filename + raf_b + filename + raf_c)