利用notepad++ 的 pythonscript 批量修改文件编码为UTF-8

import os
import sys

def get_filepath(dir_path, list_name):
    """getfiles"""
    for file in os.listdir(dir_path):  # getFiles
        file_path = os.path.join(dir_path, file)  # getFullPath
        if os.path.isdir(file_path):  # getFiles
            get_filepath(file_path, list_name)
        else:
            list_name.append(file_path)  # save
    return list_name

 
def convertFiles(files):
    """convert encode"""
    for file in files:
        print(file)
        if file[-4:] == '.txt' or file[-3:] == '.py':  # Specify type of the files
            notepad.open(file)
            notepad.runMenuCommand("Encoding", "Convert to UTF-8-BOM")
            notepad.save()
            notepad.close()

if __name__ == "__main__":
    # Path to the folder with files to convert
    dir_to_convert = "C:\\Users\\Administrator\\Desktop\\pythonm\\"
    files=list()
    files=get_filepath(dir_to_convert,files)
    convertFiles(files)

你可能感兴趣的:(python专栏,notepad++)