There is currently no good way to recursively scan through a
directory-structure and collect files/results.
File.eachFileRecurse and all of the overloads and derivatives don't
return a result, and thus makes it awkward
to use in a streaming fashion. One needs to create an external container
and use it in the closure to collect its results.
I propose adding a new collectFilesRecurse(Filetype,Closure) [along with
its overloads and derivatives]
which works like Iterables.findResults, in that it only collect non-null
results.
Example
// Current Groovy
List<String> input // some list of files
List<File> resultsFiles = []
input.collect{
new File(it)
}.findAll{
it.directory
}.eachFileRecurse {
if (it.name.endsWith('.properties')) {
results << it
}
}
List<Properties> results = resultFiles.collect {
extractData(it)
}
---------
// With collectFileRecurse
List<Properties> results = input.collect{
new File(it)
}.findAll{
it.directory
}.collectFileRecurse {
it.name.endsWith('.properties') ? it : null
}.collect {
extractData(it)
}
Thoughts?
-Leo