- # 目录树
- import os
- def travelTree(currentPath, count):
- if not os.path.exists(currentPath):
- return
- if os.path.isfile(currentPath):
- fileName = os.path.basename(currentPath)
- print '\\t' * count + '├── ' + fileName
- elif os.path.isdir(currentPath):
- print '\\t' * count + '├── ' + currentPath
- pathList = os.listdir(currentPath)
- for eachPath in pathList:
- travelTree(currentPath + '/' + eachPath, count + 1)
- travelTree('E:\\updata', 1)
- #该片段来自于http://www.codesnippet.cn/detail/2812201514316.html
来源: http://www.codesnippet.cn/detail/2812201514316.html