Skip to content
On this page

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

class · Ruby 4.1

File::Stat

< Object include Comparable 43 instance methods 1 class methods

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):

Example
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.

Class methods 1

Instance methods 43

Ruby version changes 1

  1. 4.0