Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
File#birthtime
() -> ::Time
birthtime → new_time
file.c
View on GitHub ↗
static VALUE
rb_file_birthtime(VALUE obj)
{
rb_io_t *fptr;
rb_io_stat_data st;
GetOpenFile(obj, fptr);
if (fstatx_without_gvl(fptr, &st, STATX_BTIME) == -1) {
rb_sys_fail_path(fptr->pathv);
}
return statx_birthtime(&st);
}
Returns a new Time object containing the create time for self:
Example
filepath = 't.tmp' File.write(filepath, 'foo') file = File.new(filepath) file.birthtime # => 2026-04-14 15:53:45.002656 -0500 File.write(filepath, 'bar') file.birthtime # => 2026-04-14 15:53:45.002656 -0500 file.close File.delete(filepath) file.birthtime # Raises IOError: closed stream