Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 547
ryan1393402 Avatar asked May 14 '12 09:05

ryan1393402


People also ask

How can I get the date modified of a 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.

What is file modified date?

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.

What does __ file __ mean in Ruby?

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.


1 Answers

Use mtime:

File.mtime("testfile") => 2014-04-13 16:00:23 -0300 
like image 194
Constantine M Avatar answered Sep 20 '22 03:09

Constantine M