The stat
property returns the status or information about a particular file. The ctime
of stat
represents the time at which the directory information of a file is changed, but not the file itself.
File.stat(filename).ctime
filename
: This is the file for which we want the change time.This method returns the change time for the file as a Time
object.
Let's look at the code below:
# get file and print its change timeputs "The change time of this file is:"puts File.stat("main.rb").ctime
ctime
to get the change time of the main.rb
file, and we print it to the console.