Topic: How do I sort Find.find by modified date?

How can I sort the files by modified date using code such as this?

Find.find(@member_dir) do |f|

Or, is there a better option than the Find.find method out there?

Thanks in advance.

Re: How do I sort Find.find by modified date?

I don't know if this is what you need:

@files = File.find(:all, :order => "created_on")

More details about find method.

Re: How do I sort Find.find by modified date?

I don't see a "find" method in the "File" class.?
http://www.ruby-doc.org/core/classes/File.html

This is what I'm currently doing but wish there was a shorter way:

@files = []

Find.find(@member_dir) do |path|
     file_stat = File.stat path
     @files << {
               :name => File.basename(path),
               :mtime => file_stat.mtime
     }
end

@files = @files.sort_by { |file| file[:mtime] }.reverse

Re: How do I sort Find.find by modified date?

Forget about the code I gave! I've wrote the reply just before taking my nap hmm (I thought that you are finding files in a File model (DB Table), and even this is wrong because File is not allowed for table names).