How to read all files in a directory

Hung Vo hungbichvo at yahoo.com
Mon Nov 7 16:42:54 CET 2005


Hello Larry,
 
Thanks a lot for your response. It helps me a lot. 
 
I used your suggestion and got an error:
    path=r'C:\datafiles\'
                                ^
SyntaxError: EOL while scanning single-quoted string

Then, I changed just a little bit and it works fine.
I set path='C:\\datafiles\\' instead of path=r'C:\datafiles\'

Again Larry, I appreciate your suggestion
 
Hung Vo.

Larry Bates <larry.bates at websafe.com> wrote:
Not tested:

import glob
import os
path=r'C:\datafiles\'
for fileName in glob.glob(os.path.join(path,'*.DAT')):
dataFile=open(fileName, 'r').readlines()
.
. Continue yur code here
.



-Larry Bates
hungbichvo wrote:
> Dear All,
> 
> My python application is small. It reads data from a file.
> My code is:
> fileName = '900128.DAT'
> dataFile = open(fileName, 'r').readlines()
> I have to run 100 input files .DAT. Each time I run application, I have 
> to change code fileName to a new one. For example, fileName 
> = 'NewFile.DAT'.
> I do not know how I can process all file with extension .DAT in a 
> specific directory once only.
> 
> Any suggestion will be appreciated,
> 
> Thank you.
> 
> 
> 



		
---------------------------------
 Yahoo! FareChase - Search multiple travel sites in one click.  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20051107/7c1b4b9f/attachment.html>


More information about the Python-list mailing list