Ruby/Справочник/FileTest

Материал из Викиучебника

Перейти к: навигация, поиск

Содержание

[править] Класс FileTest

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).


Методы объекта

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

[править] FileTest#blockdev?


 File.blockdev?(file_name)   =>  true or false

Returns true if the named file is a block device.

[править] FileTest#chardev?


 File.chardev?(file_name)   =>  true or false

Returns true if the named file is a character device.

[править] FileTest#directory?


 File.directory?(file_name)   =>  true or false

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

  File.directory?(".")

[править] FileTest#executable?


 File.executable?(file_name)   => true or false

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

[править] FileTest#executable_real?


 File.executable_real?(file_name)   => true or false

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

[править] FileTest#exist?


 File.exist?(file_name)    =>  true or false
 File.exists?(file_name)   =>  true or false    (obsolete)

Return true if the named file exists.

[править] FileTest#exists?


 File.exist?(file_name)    =>  true or false
 File.exists?(file_name)   =>  true or false    (obsolete)

Return true if the named file exists.

[править] FileTest#file?


 File.file?(file_name)   => true or false

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

[править] FileTest#grpowned?


 File.grpowned?(file_name)   => true or false

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.

[править] FileTest#identical?


 File.identical?(file_1, file_2)   =>  true or false

Returns true if the named files are identical.

   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

[править] FileTest#owned?


 File.owned?(file_name)   => true or false

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

[править] FileTest#pipe?


 File.pipe?(file_name)   =>  true or false

Returns true if the named file is a pipe.

[править] FileTest#readable?


 File.readable?(file_name)   => true or false

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

[править] FileTest#readable_real?


 File.readable_real?(file_name)   => true or false

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

[править] FileTest#setgid?


 File.setgid?(file_name)   =>  true or false

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

[править] FileTest#setuid?


 File.setuid?(file_name)   =>  true or false

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

[править] FileTest#size


 File.size(file_name)   => integer

Returns the size of file_name.

[править] FileTest#size?


 File.file?(file_name)   => integer  or  nil

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

[править] FileTest#socket?


 File.socket?(file_name)   =>  true or false

Returns true if the named file is a socket.

[править] FileTest#sticky?


 File.sticky?(file_name)   =>  true or false

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

[править] FileTest#symlink?


 File.symlink?(file_name)   =>  true or false

Returns true if the named file is a symbolic link.

[править] FileTest#writable?


 File.writable?(file_name)   => true or false

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

[править] FileTest#writable_real?


 File.writable_real?(file_name)   => true or false

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

[править] FileTest#zero?


 File.zero?(file_name)   => true or false

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