…/xxxxx/为要合并的目录名
from pathlib import Path
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:[email protected]
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