The ctime()
method of a File instance in Ruby is used to return the change time for a particular file. Note that this time is when the file’s directory was changed, not the file itself.
File.ctime(file_name)
file_name
is the name of the file.
The value returned is the directory change time for the file.
# get filefn1 = "test.txt"fn2 = "test.rb"# get change timeputs File.ctime(fn1)puts File.ctime(fn2)
test.rb
and test.txt
were created. We also have the main.rb
file containing our application code.