Forum Discussion

_ivanovich_'s avatar
Frequent Contributor
5 years ago

How to get all last modified files from a directory with groovy?

Hi, this line gets the last modified file from a directory. new File(myfolder).listFiles()?.sort { -it.lastModified() }?.head() How to get all files from the same folder? Thank you
  • _ivanovich_'s avatar
    5 years ago

    resoleved with this:

    .findAll(recent).groupBy{'-')[1]}.collect{owner, logs -> logs.sort{a,b -> a.lastModified() <=> b.lastModified()} }.flatten()
    .each{ println "${}" }