用户登录
用户注册

分享至

groovy实现的简易tree命令

  • 作者: 奇葩硬汉123308678
  • 来源: 51数据库
  • 2022-08-17
path = "." as File
if (args) {
    path = args[0] as File
}
printDir path,0

def printDir(File path, int depth,boolean isLast = false, String nextLinePre = "") {
    if (depth > 0) {
        if (isLast) {
            print '└'
            nextLinePre += "    "
        } else {
            print '├'
            nextLinePre += "│   "
        }
        print '── '
    }

    println path.name
    if (path.isDirectory()) {
        File[] files = path.listFiles()
        files.each {
            print nextLinePre
            if (it == files.last())
                printDir(it, depth+1, true, nextLinePre)
            else
                printDir(it, depth+1, false, nextLinePre)
        }
    }
}
软件
前端设计
程序设计
Java相关