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)
利用notepad++ 的 pythonscript 批量修改文件编码为UTF-8
最新推荐文章于 2024-06-13 10:52:24 发布