[Tutor] list.index() question

Alan Gauld alan.gauld at btinternet.com
Tue Dec 9 01:47:17 CET 2008


"Damon Timm" <damontimm at gmail.com> wrote

> walk the directory path, I want to see if a directory contains any
> files ending in a certain type ... if it does, I wanna do some stuff

Check out the glob module.

> for dirpath, subFolders, files in os.walk(rootDir):
>     try:
>         i = files.index("*.flac") #how do I make it search for files
> that end in ".flac" ?

If yu call glob.glob() with the dirpath you will get a list of all
the flac files in the current dir.

HTH,


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 




More information about the Tutor mailing list