Python脚本-输出文件目录树

2015-09-21 0 390
Python脚本-输出文件目录树
# 目录树
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)

遇见资源网 python Python脚本-输出文件目录树 http://www.ox520.com/15776.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务