Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

class method

File.ctime

(::path | ::IO file_name) -> ::Time
File.ctime(object) → time

On Windows, returns the birthtime for object.

On other systems, returns a new Time object containing the time of the most recent metadata change to the entry represented by object, which is a string path or an IO object; see File System Timestamps:

Example
dirpath = '/tmp/dir'
Dir.mkdir(dirpath)
File.ctime(dirpath)                    # => 2026-10-05 16:24:40.347201215 -0500
# Create file therein; file ctime established; directory ctime updated.
filepath = File.join(dirpath, 't.tmp') # => "/tmp/dir/t.tmp"
File.write(filepath, 'foo')
File.ctime(dirpath)                    # => 2026-10-05 16:25:34.790762181 -0500
File.ctime(filepath)                   # => 2026-10-05 16:25:34.790762181 -0500
# Write file; file ctime updated; directory ctime not updated.
File.write(filepath, 'bar')
File.ctime(dirpath)                    # => 2026-10-05 16:25:34.790762181 -0500
File.ctime(filepath)                   # => 2026-10-05 16:26:23.030432041 -0500
# Read file; neither ctime updated.
File.read(filepath)
File.ctime(dirpath)                    # => 2026-10-05 16:25:34.790762181 -0500
File.ctime(filepath)                   # => 2026-10-05 16:26:23.030432041 -0500
FileUtils.rm_rf(dirpath)               # Clean up.
See also #ctime .chown .delete .chmod also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0