Created
August 21, 2014 21:44
-
-
Save vaidik/bed54ca28a61d1ae0b99 to your computer and use it in GitHub Desktop.
Python: Outward Walk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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