Skip to content

Instantly share code, notes, and snippets.

@BlogBlocks
Last active December 19, 2017 00:22
Combines all *.txt files in a directory into one
# Combines all *.txt files in a directory into one
# NOTICE: it is saved as a .text extension.
# That is so it will not be read as a result file of a new search
import time, glob
clean=open("test.text");clean.close()
#outfilename = 'all_' + str((int(time.time()))) + ".txt"
outfilename = "test.text"
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)
print outfilename
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment