Skip to content

Instantly share code, notes, and snippets.

@arunkarnann
Created July 25, 2019 05:18
Show Gist options
  • Save arunkarnann/fe7740e0881c0c251e1ff783c60add1c to your computer and use it in GitHub Desktop.
Save arunkarnann/fe7740e0881c0c251e1ff783c60add1c to your computer and use it in GitHub Desktop.
Merges all txt file the current folder and create a new file with all contents
import shutil
import glob
outfilename = "all.txt"
with open(outfilename, 'wb') as outfile:
for filename in glob.glob('*.txt'):
if filename == outfilename:
# don't want to copy the output into the output
continue
with open(filename, 'rb') as readfile:
shutil.copyfileobj(readfile, outfile)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment