Listing files with special names

Quinn Dunkan quinn at euro.ugcs.caltech.edu
Mon Sep 11 16:30:04 EDT 2000


On 9 Sep 2000 23:21:47 GMT, Gustaf Liljegren <gustafl at algonet.se> wrote:
>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?

Yep... see the glob module.

txt_files = glob.glob('/path/to/dir/*.txt')



More information about the Python-list mailing list