Hey!
What is the easiest way to retrieve the oldest (oldest modification
date) file from a directory?
thx ck
Hey!
What is the easiest way to retrieve the oldest (oldest modification
date) file from a directory?
thx ck
2008/4/10, Christian K. [email protected]:
Hey!
What is the easiest way to retrieve the oldest (oldest modification
date) file from a directory?
def oldest_file(dir)
Dir.entries(dir).map { |e|
File.join(dir, e)
}.select { |f|
File.file? f
}.sort_by { |f|
File.mtime f
}.first
end
This ignores directories.
Stefan L. wrote:
def oldest_file(dir)
Dir.entries(dir).map { |e|
File.join(dir, e)
}.select { |f|
File.file? f
}.sort_by { |f|
File.mtime f
}.first
end
Perfect, Thx!
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs