Re: newb question: file searching




jaysherby@xxxxxxxxx wrote:
Mike Kent wrote:
What you want is os.walk().

http://www.python.org/doc/current/lib/os-file-dir.html

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?

Not completely. According to the documentation, os.walk returns a
tuple:
(directory, subdirectories, files)
So the files you want are in the third element of the tuple.

You can use the fnmatch module to find the names that match your
filename pattern.

You'll want to do something like this:

for (dir, subdirs, files) in os.walk('.'):
.... for cppFile in fnmatch.filter(files, '*.cpp'):
.... print cppFile
....
ActiveX Test.cpp
ActiveX TestDoc.cpp
ActiveX TestView.cpp
MainFrm.cpp
StdAfx.cpp


Please note that your results will vary, of course.

.



Relevant Pages

  • Re: Listbox formatting help (coloring of specific rows)
    ... vb6 would work unbound for access downloads an eval, ... sorts of criteria colouring etc, ... > Is there any sort of ActiveX component or 3rd party solution ...
    (microsoft.public.access.forms)
  • Re: Lookup Table Dilemma
    ... I remember reading your original post and, yes, it was confusing! ... >> wouldn't meet the minimum value criteria, ... >> only problem is that the lookup table has to be in a separate sheet tab. ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Hypochondria sucks
    ... I'm just asking what criteria the poster is ... I'm also curious why I got such a defensive response from you. ... you are reading much more into the question than was there. ... My question wasn't rude or defensive; ...
    (alt.support.diabetes)
  • Re: Older SF
    ... Of course there's a huge gray area between those criteria, ... Let's see -- my father was born in1908, my mother in 1912, I started reading SF ... around 1942 -- ERB Mars books that my mother loved, ...
    (rec.arts.sf.written)
  • Re: newb question: file searching
    ... Mike Kent wrote: ... If I'm reading this correctly, ... and then add that info to whatever datatype I want to make a little ... (do whatever to decide if criteria is met, ...
    (comp.lang.python)