Listing files with special names

Jordan Katz katz at
Sun Sep 10 01:58:10 CEST 2000

gustafl at (Gustaf Liljegren) writes:

> I bet there's a function for this, but I can't find it. I have directory 
> with several files and want a list of all files with names ending with 
> "*.txt". os.listdir() is as close as I get, but as I get all files with 
> that I guess I have to run a regexp on them to aquire only the textfiles. 
> Any easier way?

The `glob' module does this for you:

import glob

Jordan Katz <katz at>

More information about the Python-list mailing list