What is stat.ctime in Ruby?

Overview

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.

Syntax

File.stat(filename).ctime
stat.ctime syntax in Ruby

Parameters

  • filename: This is the file for which we want the change time.

Return value

This method returns the change time for the file as a Time object.

Code example

Let's look at the code below:

# get file and print its change time
puts "The change time of this file is:"
puts File.stat("main.rb").ctime

Code explanation

  • Lines 2 and 3: We use ctime to get the change time of the main.rb file, and we print it to the console.

Free Resources