- Inheritance
- < Object
- Included Modules
- Comparable
Objects of class File::Stat encapsulate common status information for File objects. The information is recorded at the moment the File::Stat object is created; changes made to the file after that point will not be reflected. File::Stat objects are returned by IO#stat, File::stat, File#lstat, and File::lstat. Many of these methods return platform-specific values, and not all values are meaningful on all systems. See also Kernel#test.
Methods
Class
Visibility | Signature |
---|---|
public | new (p1) |
Instance
Visibility | Signature |
---|---|
public | <=> (p1) |
public | atime () |
public | blksize () |
public | blockdev? () |
public | blocks () |
public | chardev? () |
public | ctime () |
public | dev () |
public | dev_major () |
public | dev_minor () |
public | directory? () |
public | executable? () |
public | executable_real? () |
public | file? () |
public | ftype () |
public | gid () |
public | grpowned? () |
public | ino () |
public | inspect () |
public | mode () |
public | mtime () |
public | nlink () |
public | owned? () |
public | pipe? () |
public | pretty_print (q) |
public | rdev () |
public | rdev_major () |
public | rdev_minor () |
public | readable? () |
public | readable_real? () |
public | setgid? () |
public | setuid? () |
public | size () |
public | size? () |
public | socket? () |
public | sticky? () |
public | symlink? () |
public | uid () |
public | writable? () |
public | writable_real? () |
public | zero? () |
Class Method Detail
File::Stat.new(file_name) => stat
Create a File::Stat object for the given file name (raising an exception if the file doesn‘t exist).
Instance Method Detail
stat <=> other_stat => -1, 0, 1
Compares File::Stat objects by comparing their respective modification times.
f1 = File.new("f1", "w") sleep 1 f2 = File.new("f2", "w") f1.stat <=> f2.stat #=> -1
stat.atime => time
Returns the last access time for this file as an object of class Time.
File.stat("testfile").atime #=> Wed Dec 31 18:00:00 CST 1969
stat.blksize => integer or nil
Returns the native file system‘s block size. Will return nil on platforms that don‘t support this information.
File.stat("testfile").blksize #=> 4096
stat.blockdev? => true or false
Returns true if the file is a block device, false if it isn‘t or if the operating system doesn‘t support this feature.
File.stat("testfile").blockdev? #=> false File.stat("/dev/hda1").blockdev? #=> true
stat.blocks => integer or nil
Returns the number of native file system blocks allocated for this file, or nil if the operating system doesn‘t support this feature.
File.stat("testfile").blocks #=> 2
stat.chardev? => true or false
Returns true if the file is a character device, false if it isn‘t or if the operating system doesn‘t support this feature.
File.stat("/dev/tty").chardev? #=> true
stat.ctime → aTime
Returns the change time for stat (that is, the time directory information about the file was changed, not the file itself).
File.stat("testfile").ctime #=> Wed Apr 09 08:53:14 CDT 2003
stat.dev => fixnum
Returns an integer representing the device on which stat resides.
File.stat("testfile").dev #=> 774
stat.dev_major => fixnum
Returns the major part of File_Stat#dev or nil.
File.stat("/dev/fd1").dev_major #=> 2 File.stat("/dev/tty").dev_major #=> 5
stat.dev_minor => fixnum
Returns the minor part of File_Stat#dev or nil.
File.stat("/dev/fd1").dev_minor #=> 1 File.stat("/dev/tty").dev_minor #=> 0
stat.directory? => true or false
Returns true if stat is a directory, false otherwise.
File.stat("testfile").directory? #=> false File.stat(".").directory? #=> true
stat.executable? => true or false
Returns true if stat is executable or if the operating system doesn‘t distinguish executable files from nonexecutable files. The tests are made using the effective owner of the process.
File.stat("testfile").executable? #=> false
stat.executable_real? => true or false
Same as executable?, but tests using the real owner of the process.
stat.file? => true or false
Returns true if stat is a regular file (not a device file, pipe, socket, etc.).
File.stat("testfile").file? #=> true
stat.ftype => string
Identifies the type of stat. The return string is one of: ``file’’, ``directory’’, ``characterSpecial’’, ``blockSpecial’’, ``fifo’’, ``link’’, ``socket’’, or ``unknown’’.
File.stat("/dev/tty").ftype #=> "characterSpecial"
stat.gid => fixnum
Returns the numeric group id of the owner of stat.
File.stat("testfile").gid #=> 500
stat.grpowned? => true or false
Returns true if the effective group id of the process is the same as the group id of stat. On Windows NT, returns false.
File.stat("testfile").grpowned? #=> true File.stat("/etc/passwd").grpowned? #=> false
stat.ino => fixnum
Returns the inode number for stat.
File.stat("testfile").ino #=> 1083669
stat.inspect => string
Produce a nicely formatted description of stat.
File.stat("/etc/passwd").inspect #=> "#<File::Stat dev=0xe000005, ino=1078078, mode=0100644, nlink=1, uid=0, gid=0, rdev=0x0, size=1374, blksize=4096, blocks=8, atime=Wed Dec 10 10:16:12 CST 2003, mtime=Fri Sep 12 15:41:41 CDT 2003, ctime=Mon Oct 27 11:20:27 CST 2003>"
stat.mode => fixnum
Returns an integer representing the permission bits of stat. The meaning of the bits is platform dependent; on Unix systems, see stat(2).
File.chmod(0644, "testfile") #=> 1 s = File.stat("testfile") sprintf("%o", s.mode) #=> "100644"
stat.mtime → aTime
Returns the modification time of stat.
File.stat("testfile").mtime #=> Wed Apr 09 08:53:14 CDT 2003
stat.nlink => fixnum
Returns the number of hard links to stat.
File.stat("testfile").nlink #=> 1 File.link("testfile", "testfile.bak") #=> 0 File.stat("testfile").nlink #=> 2
stat.owned? => true or false
Returns true if the effective user id of the process is the same as the owner of stat.
File.stat("testfile").owned? #=> true File.stat("/etc/passwd").owned? #=> false
stat.pipe? => true or false
Returns true if the operating system supports pipes and stat is a pipe; false otherwise.
pretty_print(q)
stat.rdev => fixnum or nil
Returns an integer representing the device type on which stat resides. Returns nil if the operating system doesn‘t support this feature.
File.stat("/dev/fd1").rdev #=> 513 File.stat("/dev/tty").rdev #=> 1280
stat.rdev_major => fixnum
Returns the major part of File_Stat#rdev or nil.
File.stat("/dev/fd1").rdev_major #=> 2 File.stat("/dev/tty").rdev_major #=> 5
stat.rdev_minor => fixnum
Returns the minor part of File_Stat#rdev or nil.
File.stat("/dev/fd1").rdev_minor #=> 1 File.stat("/dev/tty").rdev_minor #=> 0
stat.readable? => true or false
Returns true if stat is readable by the effective user id of this process.
File.stat("testfile").readable? #=> true
stat.readable_real? → true or false
Returns true if stat is readable by the real user id of this process.
File.stat("testfile").readable_real? #=> true
stat.setgid? => true or false
Returns true if stat has the set-group-id permission bit set, false if it doesn‘t or if the operating system doesn‘t support this feature.
File.stat("/usr/sbin/lpc").setgid? #=> true
stat.setuid? => true or false
Returns true if stat has the set-user-id permission bit set, false if it doesn‘t or if the operating system doesn‘t support this feature.
File.stat("/bin/su").setuid? #=> true
stat.size => fixnum
Returns the size of stat in bytes.
File.stat("testfile").size #=> 66
state.size => integer
Returns the size of stat in bytes.
File.stat("testfile").size #=> 66
stat.socket? => true or false
Returns true if stat is a socket, false if it isn‘t or if the operating system doesn‘t support this feature.
File.stat("testfile").socket? #=> false
stat.sticky? => true or false
Returns true if stat has its sticky bit set, false if it doesn‘t or if the operating system doesn‘t support this feature.
File.stat("testfile").sticky? #=> false
stat.symlink? => true or false
Returns true if stat is a symbolic link, false if it isn‘t or if the operating system doesn‘t support this feature. As File::stat automatically follows symbolic links, symlink? will always be false for an object returned by File::stat.
File.symlink("testfile", "alink") #=> 0 File.stat("alink").symlink? #=> false File.lstat("alink").symlink? #=> true
stat.uid => fixnum
Returns the numeric user id of the owner of stat.
File.stat("testfile").uid #=> 501
stat.writable? → true or false
Returns true if stat is writable by the effective user id of this process.
File.stat("testfile").writable? #=> true
stat.writable_real? → true or false
Returns true if stat is writable by the real user id of this process.
File.stat("testfile").writable_real? #=> true
stat.zero? => true or false
Returns true if stat is a zero-length file; false otherwise.
File.stat("testfile").zero? #=> false