Quantcast

Sorting files by lastModified()

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Sorting files by lastModified()

nabblee
What would be the grooviest way to get a list of all the files in a directory matching a certain regex pattern, sorted by their lastModified() date?

Thanks!
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Sorting files by lastModified()

Robert Fischer
Something like this:

def files = new File(dir).list({ dir, name ->
   return (name =~ /pattern/)
} as FilenameFilter) as List
files.sort { a,b -> a.lastModified() <=> b.lastModified() }

nabblee wrote:
> What would be the grooviest way to get a list of all the files in a directory
> matching a certain regex pattern, sorted by their lastModified() date?
>
> Thanks!

--
~~ Robert Fischer.
Grails Trainining      http://www.smokejumperit.com/grails_training.html
Smokejumper Consulting http://smokejumperit.com
Enfranchised Mind Blog http://enfranchisedmind.com/blog

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Sorting files by lastModified()

Dierk König
In reply to this post by nabblee

new File('.').listFiles().grep(~/.*/).sort{it.lastModified()}

or if you don't want to have the dirs

new  
File('.').listFiles().grep{it.file}.grep(~/.*/).sort{it.lastModified()}

cheers
Dierk

Am 04.12.2008 um 02:52 schrieb nabblee:

>
> What would be the grooviest way to get a list of all the files in a  
> directory
> matching a certain regex pattern, sorted by their lastModified() date?
>
> Thanks!
> --
> View this message in context: http://www.nabble.com/Sorting-files-by-lastModified%28%29-tp20825744p20825744.html
> Sent from the groovy - user mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Loading...