python3.0简单的合并txt文件

 1 import glob

 2 

 3 def GetFilePathList(folder,fileType):

 4     ''' 读取文件夹folder下的所有类型为filetype,的文件 '''

 5     return glob.glob(folder+r'\*.'+fileType)

 6 

 7 

 8 def MergeTextFile(pathList,outFilePath):

 9     '''合并pathList列表中,所有的文件,合并后的文件为outfilepath'''

10     #3.0里面从文件读取和写入中文,貌似只能使用bytes的方式????

11     

12     reFile=open(outFilePath,'wb+')

13     for p in pathList:

14         

15         f=open(p,'rb')

16         s=f.read()

17      

18         reFile.write(s)

19         f.close()

20                     

21     reFile.close()

你可能感兴趣的:(python3)