Recursive listing of all files matching a certain filetype in Groovy

前端 未结 4 443
暖寄归人
暖寄归人 2020-12-28 12:39

I am trying to recursively list all files that match a particular file type in Groovy. This example almost does it. However, it does not list the files in the root folder. I

4条回答
  •  庸人自扰
    2020-12-28 13:12

    // Define closure
    def result
    
    findTxtFileClos = {
    
            it.eachDir(findTxtFileClos);
            it.eachFileMatch(~/.*.txt/) {file ->
                    result += "${file.absolutePath}\n"
            }
        }
    
    // Apply closure
    findTxtFileClos(new File("."))
    
    println result
    

提交回复
热议问题