Created
January 6, 2014 02:09
-
-
Save conanca/8277096 to your computer and use it in GitHub Desktop.
9行python代码实现 遍历显示当前目录树
This file contains 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
from os.path import basename, isdir | |
from os import listdir | |
def traverse(path, depth=0): | |
print depth* '| ' + '|_', basename(path) | |
if(isdir(path)): | |
for item in listdir(path): | |
traverse(path+'/'+item, depth+1) | |
if __name__ == '__main__': | |
traverse('./') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment