Search code examples
ruby

Is it possible to read a file's modification date with Ruby?


Is it possible to read a file's modification date with Ruby? I have successfully opened a text file and captured the contents of the file with

File.open("test.txt", "r").each do |line|"

but it would be very useful to read the modification date of the file.


Solution

  • Use mtime:

    File.mtime("testfile")
    => 2014-04-13 16:00:23 -0300