cancel
Showing results for 
Search instead for 
Did you mean: 

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

SOLVED
Highlighted
Frequent Contributor

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

1 ACCEPTED SOLUTION

Accepted Solutions
Frequent Contributor

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

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}" }

View solution in original post

1 REPLY 1
Frequent Contributor

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

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}" }

View solution in original post

New Here?
Join us and watch the welcome video:
Watch the new Interview
Top Kudoed Authors