このコードを使用してフォルダー内の複数の TXT ファイルをマージしようとしましたが、機能しません。
import os,shutil
path = "C:/Users/user/Documents/MergeFolder"
f=open(path + "/fileappend.txt","a")
for r,d,fi in os.walk(path):
     for files in fi:
         if files.endswith(".txt"):                         
              g=open(os.path.join(r,files))
              shutil.copyfileobj(g,f)
              g.close()
f.close()
誰にもアイデアがありますか?