Skip to content

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

class method

File.size

(::path | ::IO file_name) -> ::Integer
File.size(object) → integer

Returns the size in bytes of the given object, which may be a path or an IO object:

Example
File.size('doc/maintainers.md') # => 14900  # Regular file.
File.size('doc/syntax/')        # => 4096   # Directory.
File.size($stdin)               # => 0      # IO object.
See also .size? #size .setuid? .setgid? also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0