Last active
December 19, 2017 00:22
Combines all *.txt files in a directory into one
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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