getting files in a dir and subdirs

soumitri soumitri at postmark.net
Fri May 11 15:34:27 CEST 2001


Scott Hathaway wrote:

> Does someone already have code that will return the filenames in a
directory
> and all subdirectories?  If someone has already written it, I will not have
> to start from scratch.
> 
> Thanks,
> Scott
> 

hi Scott!

I think the following works :

# print all files in the dir-tree starting at *path*
# first define a visit fn
def visit(arg, dir, names) :
     for i in names : 
           print os.path.join(dir, i)

# here, path is the starting directory :
os.path.walk(path, visit, None)

Soumitri.





More information about the Python-list mailing list