python生成文件树的代码
#!/usr/bin/python from os.path import basename, isdir from os import listdir def traverse(path, depth=0): prefix = depth* '| ' + '|_' if(isdir(path)): print prefix, basename(path) for item in listdir(path): traverse(path+'/'+item, depth+1) else: print prefix, basename(path) if __name__ == '__main__': traverse('./')
|