Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
File::Stat#zero?
() -> bool
zero? → true or false
file.c
View on GitHub ↗
static VALUE
rb_stat_z(VALUE obj)
{
if (get_stat(obj)->ST_(size) == 0) return Qtrue;
return Qfalse;
}
Returns whether the entry at the path in self has size zero.
The entry may be a file:
Example
filepath = '/tmp/t.tmp' File.write(filepath, 'foo') File.stat(filepath).zero? # => false File.truncate(filepath, 0) File.stat(filepath).zero? # => true File.delete(filepath) # Clean up.
The entry may be a directory:
Example
dirpath = '/tmp/foo' Dir.mkdir(dirpath) stat = File.stat(dirpath) # Size is filesystem-dependent; may or may not be zero. stat.size # => 4096 stat.zero? # => false filepath = File.join(dirpath, 't.tmp') # => "/tmp/foo/t.tmp" File.write(filepath, 'foo') stat = File.stat(dirpath) stat.size # => 4096 stat.zero? # => false FileUtils.rm_rf(dirpath) # Clean up.