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.
Windows file properties You can also see the modified date by viewing the file properties. Right-click the file and select Properties. In the Properties window, the Created date, Modified date, and Accessed date is displayed, similar to the example below.
The name already says it all. The File Modification Date/Time indicates the last date and time at which the file has been modified. This date and time-stamp is shown in a certain format. The date is shown first in the YYYY:MM:DD format, for example 2017:03:29 for March 29th 2017.
The value of __FILE__ is a relative path that is created and stored (but never updated) when your file is loaded. This means that if you have any calls to Dir.
Use mtime
:
File.mtime("testfile") => 2014-04-13 16:00:23 -0300
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With