Andrew,

I put in your code, exactly as you have it, with only three changes:

#!/usr/bin/python
import os

for (dirpath, subdirs, filenames) in os.walk("/python24"):    # a comma instead of a period after dirpath
       for file in filenames:
               if file.endswith(".py"):                                      # py instead of baz, just for my machine
                       print os.path.join(dirpath,file)                   # file instead of f

This walks the directories and prints out the path and filename.

On a side note I've never had a problem throwing several thousand files or lines at python.

On 1/30/06, Andrew D. Fant <[EMAIL PROTECTED]> wrote:
I'm working on a program to do some processing on a directory tree. If I had
been doing it in a shell script, the core of the processing would have been in
a "find $ROOT -type f -name FOO -print" command"

On the web, I found a snippet of code that demonstrated the os.walk module and
I created a simple test program to work on my tree that looked like this:

#!/usr/bin/python
import os

for (dirpath. subdirs, filenames) in os.walk("/foo/bar"):
        for file in filenames:
                if file.endswith(".baz"):
                        print os.path.join(dirpath,f)


when I try to run it, I get a "ValueError: too many values to unpack" which I
think  comes from the fact that there is a subdirectory of /foo/bar which has
over 2500 files in it.  The tree can't be easily restructured for legacy
reasons.  Can anyone suggest the best way to get around this in code?

Thanks,
        Andy

--
Andrew Fant    | And when the night is cloudy    | This space to let
Molecular Geek | There is still a light          |----------------------
[EMAIL PROTECTED] | That shines on me               | Disclaimer:  I don't
Boston, MA     | Shine until tomorrow, Let it be | even speak for myself

_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to