美文网首页
python 合并文件夹里同类型文件

python 合并文件夹里同类型文件

作者: likc | 来源:发表于2019-10-18 15:08 被阅读0次
    import os
    
    # 批量文件目录
    srcdir = "G:\\t2"
    # 合成文件地址和名字
    destpath = "G:\\t2.txt"
    # 批量文件是否包含头文件
    containTitle = True
    filelist = os.listdir(srcdir)
    destfile = open(destpath, 'w')
    topfileidx = 0
    for item in filelist:
        filepath = srcdir + '/' + item
        line = 0
        for txt in open(filepath, 'r'):
            if containTitle == False or (containTitle == True and (topfileidx == 0 and line == 0) or line == 1):
                destfile.write(txt)
            line += 1
        topfileidx += 1
    destfile.close()
    
    

    相关文章

      网友评论

          本文标题:python 合并文件夹里同类型文件

          本文链接:https://www.haomeiwen.com/subject/gywimctx.html