Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
class method
File.birthtime
(::path | ::IO file_name) -> ::Time
File.birthtime(path) → time
file.c
View on GitHub ↗
static VALUE
rb_file_s_birthtime(VALUE klass, VALUE fname)
{
rb_io_stat_data st;
if (rb_statx(fname, &st, STATX_BTIME) < 0) {
int e = errno;
FilePathValue(fname);
rb_syserr_fail_path(e, fname);
}
return statx_birthtime(&st);
}
Returns a new Time object containing the creation time of the entry at the given path; see File System Timestamps:
Example
filepath = '/tmp/t.tmp' File.birthtime(filepath) # Raises Errno::ENOENT: No such file or directory. File.write(filepath, 'foo') File.birthtime(filepath) # => 2026-10-05 13:41:02.330337383 -0500 File.delete(filepath) # Clean up.