[Tutor] Help search files

Alan Gauld alan.gauld at btinternet.com
Wed Jul 4 19:55:51 CEST 2007

"Alejandro Decchi" <adecchi at gmail.com> wrote

> Is the word or part of the word that the user enters in the texbox .
> And this word is the name of the file to be found

Ok, In that case use the glob function in the glob module.
It returns a list of all files that match a pattern:

>>> import glob
>>> files = glob.glob("*.txt")
>>> print files

For more powerful searches you can use os.walk()

See the OS topic in my tutorial for more examples of
using glob and os.walk


Alan Gauld
Author of the Learn to Program web site

More information about the Tutor mailing list