Module

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 Methods

Returns true if the named file is a block device.

file_name can be an IO object.

Returns true if the named file is a character device.

file_name can be an IO object.

Returns true if the named file is a directory, or a symlink that points at a directory, and false otherwise.

file_name can be an IO object.

File.directory?(".")
An alias for zero?

Returns true if the named file is executable by the effective user and group id of this process. See eaccess(3).

Returns true if the named file is executable by the real user and group id of this process. See access(3).

Return true if the named file exists.

file_name can be an IO object.

“file exists” means that stat() or fstat() system call is successful.

Deprecated method. Don’t use.

Returns true if the named file exists and is a regular file.

file can be an IO object.

If the file argument is a symbolic link, it will resolve the symbolic link and use the file referenced by the link.

Returns true if the named file exists and the effective group id of the calling process is the owner of the file. Returns false on Windows.

file_name can be an IO object.

Returns true if the named files are identical.

file_1 and file_2 can be an IO object.

open("a", "w") {}
p File.identical?("a", "a")      #=> true
p File.identical?("a", "./a")    #=> true
File.link("a", "b")
p File.identical?("a", "b")      #=> true
File.symlink("a", "c")
p File.identical?("a", "c")      #=> true
open("d", "w") {}
p File.identical?("a", "d")      #=> false

Returns true if the named file exists and the effective used id of the calling process is the owner of the file.

file_name can be an IO object.

Returns true if the named file is a pipe.

file_name can be an IO object.

Returns true if the named file is readable by the effective user and group id of this process. See eaccess(3).

Returns true if the named file is readable by the real user and group id of this process. See access(3).

Returns true if the named file has the setgid bit set.

Returns true if the named file has the setuid bit set.

Returns the size of file_name.

file_name can be an IO object.

Returns nil if file_name doesn’t exist or has zero size, the size of the file otherwise.

file_name can be an IO object.

Returns true if the named file is a socket.

file_name can be an IO object.

Returns true if the named file has the sticky bit set.

Returns true if the named file is a symbolic link.

If file_name is readable by others, returns an integer representing the file permission bits of file_name. Returns nil otherwise. The meaning of the bits is platform dependent; on Unix systems, see stat(2).

file_name can be an IO object.

File.world_readable?("/etc/passwd")           #=> 420
m = File.world_readable?("/etc/passwd")
sprintf("%o", m)                              #=> "644"

If file_name is writable by others, returns an integer representing the file permission bits of file_name. Returns nil otherwise. The meaning of the bits is platform dependent; on Unix systems, see stat(2).

file_name can be an IO object.

File.world_writable?("/tmp")                  #=> 511
m = File.world_writable?("/tmp")
sprintf("%o", m)                              #=> "777"

Returns true if the named file is writable by the effective user and group id of this process. See eaccess(3).

Returns true if the named file is writable by the real user and group id of this process. See access(3)

Returns true if the named file exists and has a zero size.

file_name can be an IO object.