Forum Discussion

_ivanovich_'s avatar
_ivanovich_
Frequent Contributor
5 years ago
Solved

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

  • resoleved with this:

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

1 Reply

  • _ivanovich_'s avatar
    _ivanovich_
    Frequent Contributor

    resoleved with this:

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