Created
May 25, 2012 09:57
-
-
Save rswofxd/2787071 to your computer and use it in GitHub Desktop.
Python:目录树遍历和生成
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
#coding:utf-8 | |
import sys | |
reload(sys) | |
sys.setdefaultencoding('utf8') | |
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