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
file.c
View on GitHub ↗
static VALUE
rb_file_s_ctime(VALUE klass, VALUE fname)
{
struct stat st;
if (rb_stat(fname, &st) < 0) {
int e = errno;
FilePathValue(fname);
rb_syserr_fail_path(e, fname);
}
return stat_time(stat_ctimespec(&st));
}
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.