用户登录
用户注册

分享至

Python脚本-输出文件目录树

  • 作者: 哎呦卧草
  • 来源: 51数据库
  • 2022-08-12
# 目录树
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)
软件
前端设计
程序设计
Java相关