Python script read multiple files from a folder

Python script for read multiple files from a folder and write it in a separate single file.

Source Code:

import sys,os
path = “/home/jayapal/Desktop/route/”
fn = ‘/home/jayapal/Desktop/mapping/dem.txt’
target =open(fn, ‘w’)
for filename in os.listdir(path):
         source = open(path + filename, “r”)
         target.write(source.read())
         source.close()
target.close()

*****************************************************************************

Here fn :Output file
path :Path of folder which contain infinite files

Enjoy
Jayapal

Today's Top Articles:

Scroll to Top