file handling

Martin von Loewis loewis at informatik.hu-berlin.de
Thu Aug 10 15:44:46 EDT 2000


tjernstrom at my-deja.com writes:

> I have written a small script that process html-files. All I need to do
> is find a way to send all html files in a directory to this file while
> ignoring the rest of the files in this directory (and do the same for
> all the subdirectories).

For a single directory, os.listdir gives a list of file names; you
could filter the .html files yourself. Or you could use glob.glob to
filter *.html.

For a hierarchy, you can use os.path.walk; again, you'd have to filter
file names yourself - there is no recursive version of
glob.glob. However, the filtering can be easily done with
fnmatch.fnmatch.

Regards,
Martin



More information about the Python-list mailing list