Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return the list of files from Groovy's eachFile() in reverse order

Tags:

groovy

I'm using eachFile(), but I'm trying to reverse the order that the iteration happens. How do I do that? Right now, it appears to sort the list of files and then process each one in sorted order. I essentially want to reserve-sort that list and start from the end.

like image 560
Tony Stark Avatar asked Dec 11 '22 14:12

Tony Stark


1 Answers

I believe you can't alter the order of eachFile(), but you can achieve the desired effect.

Consider:

new File("desired dir").listFiles().sort{ it.name }.reverse().each { def f ->
    println f.name
}
like image 89
Michael Easter Avatar answered Feb 16 '23 01:02

Michael Easter