Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to iterate files recursively in Groovy?

Tags:

groovy

Is it possible to iterate files in Groovy recursively? Currently I'm using FileUtils.iterateFiles() from Apache commons-io, but maybe there is some Groovy-native alternative for the same?

like image 957
yegor256 Avatar asked Mar 13 '11 10:03

yegor256


1 Answers

Absolutely, you should check the documentation for File in Groovy. It's available here and gives you a few different helper methods to iterate recursively over a file structure.

// Simplest possible example, iterating over each file in every subfolder
new File('.').eachFileRecurse { println it.name }
like image 135
xlson Avatar answered Oct 23 '22 01:10

xlson