import os
path ='csv文件路径'
targetPath = '转换编码保存路径'
def getfiles(path):
path_collection=[]
for dirpath,dirnames,filenames in os.walk(path):
for file in filenames:
fullpath=os.path.join(dirpath,file)
path_collection.append(fullpath)
return path_collection
def covertCode(file):
sourcefile = open(file,'r')
s = sourcefile.read()
sourcefile.close()
targetFile = getTargetFile(file,targetPath)
tf = open(targetFile,"w")
a = s.decode("utf-8").encode("utf-8-sig")
tf.write(a)
tf.close()
def getTargetFile(file,targetpath):
filename = os.path.basename(file)
targetfile = os.path.join(targetpath,filename)
return targetfile
for file in getfiles(path):
covertCode(file)