Programming Ruby

The Pragmatic Programmer's Guide

Previous < Contents ^
Next >
module FileTest

Index:

blockdev? chardev? directory? executable? executable_real? exist? exists? file? grpowned? owned? pipe? readable? readable_real? setgid? setuid? size size? socket? sticky? symlink? writable? writable_real? zero?


FileTest implements file test operations similar to those used in File::Stat.

instance methods
blockdev? FileTest.blockdev?( aString ) -> true or false

Returns true if the named file is a block device, false if it isn't or if the operating system doesn't support this feature.

FileTest.blockdev?( "testfile" ) » false

chardev? FileTest.chardev?( aString ) -> true or false

Returns true if the named file is a character device, false if it isn't or if the operating system doesn't support this feature.

FileTest.chardev?( "/dev/tty" ) » true

directory? FileTest.directory?( aString ) -> true or false

Returns true if this named file is a directory, false otherwise.

FileTest.directory?( "." ) » true

executable? FileTest.executable?( aString ) -> true or false

Returns true if the named file is executable. The tests are made using the effective owner of the process.

FileTest.executable?( "testfile" ) » false

executable_real? FileTest.executable_real?( aString ) -> true or false

Same as FileTest#executable? , but tests using the real owner of the process.

exist? FileTest.exist? ( aString ) -> true or false

Returns true if the named file exists.

FileTest.exist?( "testfile" ) » true

exists? FileTest.exists? ( aString ) -> true or false

Synonym for FileTest::exist? .

file? FileTest.file?( aString ) -> true or false

Returns true if the named file is a regular file (not a device file, pipe, socket, etc.).

FileTest.file?( "testfile" ) » true

grpowned? FileTest.grpowned?( aString ) -> true or false

Returns true if the effective group id of the process is the same as the group id of the named file. On Windows NT, returns false.

FileTest.grpowned?( "/etc/passwd" ) » false

owned? FileTest.owned?( aString ) -> true or false

Returns true if the effective user id of the process is the same as the owner of the named file.

FileTest.owned?( "/etc/passwd" ) » false

pipe? FileTest.pipe?( aString ) -> true or false

Returns true if the operating system supports pipes and the named file is a pipe, false otherwise.

FileTest.pipe?( "testfile" ) » false

readable? FileTest.readable?( aString ) -> true or false

Returns true if the named file is readable by the effective user id of this process.

FileTest.readable?( "testfile" ) » true

readable_real? FileTest.readable_real?( aString ) -> true or false

Returns true if the named file is readable by the real user id of this process.

FileTest.readable_real?( "testfile" ) » true

setgid? FileTest.setgid?( aString ) -> true or false

Returns true if the named file's set-group-id permission bit is set, and false if it isn't or if the operating system doesn't support this feature.

FileTest.setgid?( "/usr/sbin/lpc" ) » true

setuid? FileTest.setuid?( aString ) -> true or false

Returns true if the named file's set-user-id permission bit is set, and false if it isn't or if the operating system doesn't support this feature.

FileTest.setuid?( "/bin/su" ) » true

size FileTest.size( aString ) -> anInteger

Returns the size of the named file in bytes.

FileTest.size( "testfile" ) » 66

size? FileTest.size?( aString ) -> aFixnum or nil

Returns nil if the named file is of zero length; otherwise, returns a nonzero aFixnum.

FileTest.size?( "testfile" ) » 66
FileTest.size?( "/dev/zero" ) » nil

socket? FileTest.socket?( aString ) -> true or false

Returns true if the named file is a socket, false if it isn't or if the operating system doesn't support this feature.

sticky? FileTest.sticky?( aString ) -> true or false

Returns true if the named file has its sticky bit set, false if it doesn't or if the operating system doesn't support this feature.

symlink? FileTest.symlink?( aString ) -> true or false

Returns true if the named file is a symbolic link, false if it isn't or if the operating system doesn't support this feature.

writable? FileTest.writable?( aString ) -> true or false

Returns true if the named file is writable by the effective user id of this process.

writable_real? FileTest.writable_real?( aString ) -> true or false

Returns true if the named file is writable by the real user id of this process.

zero? FileTest.zero?( aString ) -> true or false

Returns true if the named file is of zero length, false otherwise.


Previous < Contents ^
Next >

Extracted from the book "Programming Ruby - The Pragmatic Programmer's Guide"
Copyright © 2001 by Addison Wesley Longman, Inc. This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later (the latest version is presently available at http://www.opencontent.org/openpub/)).

Distribution of substantively modified versions of this document is prohibited without the explicit permission of the copyright holder.

Distribution of the work or derivative of the work in any standard (paper) book form is prohibited unless prior permission is obtained from the copyright holder.