123456789_123456789_123456789_123456789_123456789_

Module: FileTest

Relationships & Source Files
Defined in: file.c,
dir.c

Overview

FileTest implements file test operations similar to those used in ::File::Stat. It exists as a standalone module, and its methods are also insinuated into the ::File class. (Note that this is not done by inclusion: the interpreter cheats).

Instance Attribute Summary

Instance Method Summary

Instance Attribute Details

#directory?(dirpath) ⇒ Boolean (readonly)

Alias for File.directory?. Returns whether dirpath is a directory in the underlying file system:

Dir.exist?('/example')         # => true
Dir.exist?('/nosuch')          # => false
Dir.exist?('/example/main.rb') # => false

Same as File.directory?.

Instance Method Details

#blockdev?(object) ⇒ Boolean

Alias for File.blockdev?.

#chardev?(object) ⇒ Boolean

Alias for File.chardev?.

#empty?(object) ⇒ Boolean

Alias for File.empty?. Returns whether the given object exists and has size zero.

The given object may be the path to a directory (possibly non-existent):

dirpath = 'foo'
File.empty?(dirpath)       # => false  # Directory does not exist.
dir = Dir.mkdir(dirpath)
# The directory size is filesystem-dependent;
# for a directory with no children, may or may not be zero.
File.size?(dirpath)        # => 4096
File.empty?(dirpath)       # => false

The given object may be the path to a file (possibly non-existent):

filepath = File.join(dirpath, 't.tmp')
File.empty?(filepath)      # => false  # File does not exist.
File.write(filepath, '')
File.size(filepath)        # => 0
File.empty?(filepath)      # => true   # File exists; size zero.
File.size?(dirpath)        # => 4096
File.empty?(dirpath)       # => false
File.write(filepath, 'bar')
File.size(filepath)        # => 3
File.empty?(filepath)      # => false  # File exists; size non-zero.
FileUtils.rm_rf(dirpath)   # Clean up.

The given object may be an ::IO object:

File.empty?($stdin)         # => true

#executable?(path) ⇒ Boolean

Alias for File.executable?.

#executable_real?(file_name) ⇒ Boolean

#exist?(object) ⇒ Boolean

Alias for File.exist?.

#file?(object) ⇒ Boolean

Alias for File.file?.

#grpowned?(object) ⇒ Boolean

Alias for File.grpowned?.

#identical?(object_0, object_1) ⇒ Boolean

Alias for File.identical?.

#owned?(file_name) ⇒ Boolean

Alias for File.owned?.

#pipe?(filepath) ⇒ Boolean

Alias for File.pipe?.

#readable?(file_name) ⇒ Boolean

Alias for File.readable?.

#readable_real?(file_name) ⇒ Boolean

Alias for File.readable_real?.

#setgid?(file_name) ⇒ Boolean

Alias for File.setgid?.

#setuid?(file_name) ⇒ Boolean

Alias for File.setuid?.

#size(file_name) ⇒ Integer

Alias for File.size.

#size?(file_name) ⇒ Integer?

Alias for File.size?.

#socket?(filepath) ⇒ Boolean

Alias for File.socket?.

#sticky?(file_name) ⇒ Boolean

Alias for File.sticky?.

#symlink?(path) ⇒ Boolean

Alias for File.symlink?.

#world_readable?(file_name) ⇒ Integer?

#world_writable?(file_name) ⇒ Integer?

#writable?(file_name) ⇒ Boolean

Alias for File.writable?.

#writable_real?(file_name) ⇒ Boolean

Alias for File.writable_real?.

#zero?(object) ⇒ Boolean

Alias for File.zero?.