class File::Stat

A File::Stat object contains information about an entry in the filesystem.

Each of these methods returns a new File::Stat object. the first three follow symbolic links; the others don’t:

Snapshot

A new File::Stat object takes an immediate β€œsnapshot” of the filesystem entry at the given β€˜path’; the snapshot is never updated, regardless of changes in the entry (even its deletion):

filepath = '/tmp/t.tmp'
File.stat(filepath) # Raises Errno::ENOENT: No such file or directory.
File.write(filepath, 'foo')
stat = File.stat(filepath)
stat.birthtime # => 2026-10-03 12:19:23.723062465 -0500
File.delete(filepath)
stat.birthtime # => 2026-10-03 12:19:23.723062465 -0500

Filesystem Dependencies

Methods in a File::Stat object may return filesystem-dependent values, and not all values are meaningful on all filesystems; for example, File::Stat#blocks returns nil on a Windows filesystem, but returns an integer on others.

See also Kernel#test.