文件目录tree显示,python

#/usr/bin/python
import os 
 
def travelTree(currentPath, count=0):
    if not os.path.exists(currentPath):
        print "no current Path"
        return 
    if os.path.isfile(currentPath):
        fileName = os.path.basename(currentPath)
        print "  "*count + "|_ "+fileName 
    elif os.path.isdir(currentPath):
    	#print currentPath 
        print "  "*count + "|_ "+currentPath 
    	pathList = os.listdir(currentPath)
        for eachPath in pathList:
            travelTree(currentPath + '/' + eachPath, count + 1)
    else :
        print "
"
    	return

travelTree('/Users/liyi/Desktop')
#travelTree('/Users/liyi/Desktop/test.sh', 1)
原文地址:https://www.cnblogs.com/iois/p/6367080.html