标签:合并 === xxx orm 随笔 python imp abs dir
…/xxxxx/为要合并的目录名from pathlib import Path
#code:myhaspl@myhaspl.com
import os
fnLst=list(filter(lambda x:not x.is_dir(),Path(‘../xxxxx/‘).glob(‘**/*‘)))
open("allsrc.txt","w+").close()
i=1
with open("allsrc.txt","a") as sf:
for nowFn in fnLst:
print(i,"#",nowFn,"读取中:",end="==>")
sf.write("\n\n\n------------------\n")
sf.write("##<{}>##\n##[{}]|<===={}=====>|##\n".format(os.path.dirname(os.path.abspath(nowFn)),i,os.path.basename(nowFn)) )
#code:myhaspl@myhaspl.com
sf.write("------------------\n\n\n")
with open(nowFn) as f:
try:
sf.write(f.read())
print("写入成功...")
except:
print("{}读取错误,忽略....".format(nowFn))
sf.write("###read {} error!###\n".format(nowFn))
i+=1
python3随笔-合并所有目录及子目录的文本文件为一个文件
标签:合并 === xxx orm 随笔 python imp abs dir
原文地址:http://blog.51cto.com/13959448/2315560