Skip to content

Instantly share code, notes, and snippets.

@vaidik
Created August 21, 2014 21:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vaidik/bed54ca28a61d1ae0b99 to your computer and use it in GitHub Desktop.
Save vaidik/bed54ca28a61d1ae0b99 to your computer and use it in GitHub Desktop.
Python: Outward Walk
import os
def outward_walk(bottom, func, arg=None):
'''
Walks out of directory to the upper level directories in the path.
Usage is very similar to os.path.walk.
'''
levels = bottom.split('/')
while len(levels) > 1:
dirname = '/'.join(levels)
func(arg, dirname, os.listdir(dirname))
levels.pop()
func(arg, '/', os.listdir('/'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment