By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,985 Members | 1,575 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,985 IT Pros & Developers. It's quick & easy.

Need Script For read multiple files(.txt) from a folder

P: n/a
hi frenz I Need a Python Script For read multiple files(.txt) from a
folder and write it in a single text file....
Thanks
Mar 14 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Mar 14, 6:28*am, jai_python <jayapa...@gmail.comwrote:
hi frenz I *Need a Python Script For read multiple files(.txt) from a
folder and write it in a single text file....

Thanks
Take a look at the OS Module for the listdir funtion, you can use it
to build a list of all files in the given folder. Iterate through the
list checking to see if the file is of the correct type and if it is
then append/write it to your single file. Don't forget to flush()
your output otherwise you can easily run into memory issues.
Mar 14 '08 #2

P: n/a
use the glob module

import os, glob
dor = the path you want
for dir, subdir, files in os.walk(dor):
for file in files:
if glob.fnmatch.fnmatch(file,"*.txt"):
do what you want
Mar 14 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.