Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
File#ctime
() -> ::Time
ctime → time
file.c
View on GitHub ↗
static VALUE
rb_file_ctime(VALUE obj)
{
rb_io_t *fptr;
struct stat st;
GetOpenFile(obj, fptr);
if (fstat(fptr->fd, &st) == -1) {
rb_sys_fail_path(fptr->pathv);
}
return stat_time(stat_ctimespec(&st));
}
On Windows, returns the birthtime for the entry in self.
On other systems, returns a new Time object containing the time of the most recent metadata change to the entry in self; see File System Timestamps:
Example
# A directory. dirpath = '/tmp/dir' Dir.mkdir(dirpath) # Establishes directory ctime. dir = File.new(dirpath) # (Dir does not have method ctime; we use File.) dir.ctime # => 2026-10-05 17:23:49.406452569 -0500 # A file therein. filepath = File.join(dirpath, 't.tmp') # => "/tmp/dir/t.tmp" File.write(filepath, 'foo') # Establishes file ctime. file = File.new(filepath) file.ctime # => 2026-10-05 17:26:26.467758515 -0500 dir.ctime # => 2026-10-05 17:26:26.467758515 -0500 File.write(filepath, 'bar') # Updates file ctime; not directory ctime. file.ctime # => 2026-10-05 17:28:26.307497599 -0500 dir.ctime # => 2026-10-05 17:26:26.467758515 -0500 FileUtils.rm_rf(dirpath) # Clean up.