os.path.isfile and wildcard for directory name

Javier Collado javier.collado at gmail.com
Thu Dec 30 03:52:37 EST 2010


Hello,

2010/12/30  <smainklh at free.fr>:
> How can i do the same thing (wildcard in a directory name) in python please ?

You can get the contents of a directory with os.listdir and filter
with fnmatch.fnmatch more or less as in the example from the
documentation:
---------------------
import fnmatch
import os

for file in os.listdir('.'):
    if fnmatch.fnmatch(file, '*.txt'):
        print file
---------------------

Regards,
    Javier



More information about the Python-list mailing list