如何在Groovy中递归迭代文件?

yeg*_*256 5 groovy

是否可以递归迭代Groovy中的文件?目前我正在使用FileUtils.iterateFiles()Apache commons-io,但也许有一些Groovy本地替代方案呢?

xls*_*son 14

当然,您应该查看Groovy中的File文档.它在这里可用,并为您提供了一些不同的辅助方法,可以在文件结构上递归迭代.

// Simplest possible example, iterating over each file in every subfolder
new File('.').eachFileRecurse { println it.name }
Run Code Online (Sandbox Code Playgroud)