looping over the files in a directory

Jeremy Sanders jeremy+plusnews at jeremysanders.net
Fri May 14 12:28:01 EDT 2004


On Fri, 14 May 2004 15:32:32 +0000, Elaine Jackson wrote:

> Can anyone please tell me the actual syntax for saying something like this:
> 
> for <file> in <directory>:
>     <do something with the file>
> 
> (?) Muchas gracias.

There's also glob which may be useful depending on what you're doing, e.g.

import glob

for f in glob.glob("*.txt"):
 print f

Jeremy




More information about the Python-list mailing list