[Tutor] Replacement for os.path.walk

Michael P. Reilly arcege@speakeasy.net
Wed, 20 Mar 2002 13:26:28 -0500


On Tue, Mar 19, 2002 at 11:39:47PM +0100, Charlie Clark wrote:
> Hi all,
> 
> I remember someone posting a replacement for os.path.walk with less "magical" syntax but can't remember if it was here or the newsgroup. Does this ring a bell?

Have you tried a search of the newsgroups?  You might be able to find
what you are talking about there. <URL:http://www.python.org/search.html>

About the only thing I myself can remember is Perl's very "magical" Find.
I don't see os.path.walk as that complex.  

How about something like:

def simple_walk(dir):
  flist = []
  for fname in os.listdir(dir):
    file = os.path.join(dir, fname)
    if os.path.isdir(file):
      flist.extend( simple_walk(file) )
    else:
      flist.append( file )
  return flist

This would just return a list of the 'files' in a directory tree.

  -Arcege