Skip to content

Instantly share code, notes, and snippets.

@rswofxd
Created May 25, 2012 09:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rswofxd/2787071 to your computer and use it in GitHub Desktop.
Save rswofxd/2787071 to your computer and use it in GitHub Desktop.
Python:目录树遍历和生成
#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