newb question: file searching

hiaips rosedb0 at gmail.com
Tue Aug 8 16:55:12 EDT 2006


> I'm thinking os.walk() could definitely be a big part of my solution,
> but I need a little for info.  If I'm reading this correctly, os.walk()
> just goes file by file and serves it up for your script to decide what
> to do with each one.  Is that right?  So, for each file it found, I'd
> have to decide if it met the criteria of the filetype I'm searching for
> and then add that info to whatever datatype I want to make a little
> list for myself?  Am I being coherent?
>
> Something like:
>
> for files in os.walk(top, topdown=False):
>     for name in files:
>          (do whatever to decide if criteria is met, etc.)
>
> Does this look correct?

IIRC, repeated calls to os.walk would implement a depth-first search on
your current directory. Each call  returns a list:
[<directory name relative to where you started>, <list of files and
directories in that directory>]

--dave




More information about the Python-list mailing list