Walker, FileSystem Ranger

As a way to learn a bit of GIO from the green pastures of Python, I threw together a functional programming replacement to Python's os.walk(). The WalkerTexasRanger class takes 3 functions. One for results, one to clear the results, and one when the walk is finished.

Lets look at how we use this.

  1. import texas
  2. import gtk
  3.  
  4. def onResult(walker, dirname, dirs, files):
  5. print dirname
  6. print 'dirs:', dirs
  7. print 'files:', files
  8.  
  9. # 3 funcs, onResult, onClear, onFinish
  10. walker = texas.WalkerTexasRanger(onResult, None, lambda *a: gtk.main_quit())
  11. walker.walk('/tmp')
  12.  
  13. gtk.main()

You can get the module from here.

Comment (1)

  1. Blogos wrote:

    Thanks!

    Tuesday, March 24, 2009 at 8:27 pm #