using wild card when listing directories in python

user248237 picture user248237 · Jun 11, 2010 · Viewed 7.7k times · Source

how can I use wild cars like '*' when getting a list of files inside a directory in Python? for example, I want something like:

os.listdir('foo/*bar*/*.txt') 

which would return a list of all the files ending in .txt in directories that have bar in their name inside of the foo parent directory.

how can I do this?

thanks.

Answer

unutbu picture unutbu · Jun 11, 2010

glob.glob for the win.