From: achrist at easystreet.com (Al Christians)
Date: Tue, 06 Apr 1999 15:05:17 -0700
Subject: How to use os.path.walk method
References: <7edt95$krh$1@ash.prod.itd.earthlink.net>
Message-ID: <370A851D.F13835CE@easystreet.com>
Content-Length: 1504
X-UID: 1228                                                  

Are you sure that you've got that right?  I cut your code and
put it into a Python console, then changed the dir from 
/Windmodem/ to / and it worked for me.  Maybe you meant 'Winmodem'?

Al


Benjamin Derstine wrote:
> 
> Can anyone give me a brief example of how to use this method?  The
> documentation is somewhat unclear:
> 
> walk (path, visit, arg)
>      Calls the function visit with arguments (arg, dirname, names) for each
> directory in the directory tree rooted at path (including path itself, if it
> is a directory). The argument dirname specifies the visited directory, the
> argument names lists the files in the directory (gotten from
> os.listdir(dirname)). The visit function may modify names to influence the
> set of directories visited below dirname, e.g., to avoid visiting certain
> parts of the tree. (The object referred to by names must be modified in
> place, using del or slice assignment.)
> 
> I understand I need to define a second function for the visit argument but
> I'm unclear as to the third argument (arg) in walk() is for.  Likewise with
> the first argument in visit().  I tried a dummy function just to print the
> directories it walks like so:
> 
> import os
> 
> def visit(something, dirname, names):
>      print dirname
>      print names
>      print something
> 
> arg=None
> os.path.walk('/Windmodem/',visit,arg)
> 
> where 'Windowmodem' is a directory on my root.
> 
> But this does nothing and quits without returning any errors.
> Thanks,
> 
> Ben




