In: Computer Science
I have multiple .txt files in a folder, and i want to combine all their contents into a single .txt file
How do I go about such an operation in Python?
code :
text_files_in_folder :
output_file :
raw_code :
import glob
outfilename = 'all.txt' #output file name
filenames = glob.glob('*.txt') #filenames of all txt files
with open(outfilename,'w') as outfile: #opening output
file
for name in filenames:
if(name == outfilename): #dont't want to copy the output into the
output
continue
with open(name,'r') as readfile: #opening input file
outfile.write(readfile.read() + "\n") #writing to output
file
***do comment for queries and rate me up*****