ディレクトリ内のすべてのファイルを1つのファイルに連結するためのスクリプトを作成しました。ディレクトリ内のすべてのファイルを1つのファイルに連結するpythonスクリプト
これは
慣用のpythonの面でここ
時間がスニペットで、最適化することができます:
import time, glob
outfilename = 'all_' + str((int(time.time()))) + ".txt"
filenames = glob.glob('*.txt')
with open(outfilename, 'wb') as outfile:
for fname in filenames:
with open(fname, 'r') as readfile:
infile = readfile.read()
for line in infile:
outfile.write(line)
outfile.write("\n\n")
時間に最適ですか? "cat * .txt> all.txt"を使用してください:) –
[複数のテキストファイルを1つのテキストファイルにまとめてPythonを使って合成する]の可能な複製(http://stackoverflow.com/questions/17749058/combine-multiple-text-files- 1つのテキストファイルを使用するPython) – llb