Class: File::Stat
Overview
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
.
Instance Method Summary collapse
-
#<=>(other_stat) ⇒ -1, ...
Compares
File::Stat
objects by comparing their respective modification times. -
#atime ⇒ Time
Returns the last access time for this file as an object of class
Time
. -
#blksize ⇒ Integer?
Returns the native file system’s block size.
-
#blockdev? ⇒ Boolean
Returns
true
if the file is a block device,false
if it isn’t or if the operating system doesn’t support this feature. -
#blocks ⇒ Integer?
Returns the number of native file system blocks allocated for this file, or
nil
if the operating system doesn’t support this feature. -
#chardev? ⇒ Boolean
Returns
true
if the file is a character device,false
if it isn’t or if the operating system doesn’t support this feature. -
#ctime ⇒ aTime
Returns the change time for stat (that is, the time directory information about the file was changed, not the file itself).
-
#dev ⇒ Fixnum
Returns an integer representing the device on which stat resides.
-
#dev_major ⇒ Fixnum
Returns the major part of
File_Stat#dev
ornil
. -
#dev_minor ⇒ Fixnum
Returns the minor part of
File_Stat#dev
ornil
. -
#directory? ⇒ Boolean
Returns
true
if stat is a directory,false
otherwise. -
#executable? ⇒ Boolean
Returns
true
if stat is executable or if the operating system doesn’t distinguish executable files from nonexecutable files. -
#executable_real? ⇒ Boolean
Same as
executable?
, but tests using the real owner of the process. -
#file? ⇒ Boolean
Returns
true
if stat is a regular file (not a device file, pipe, socket, etc.). -
#ftype ⇒ String
Identifies the type of stat.
-
#gid ⇒ Fixnum
Returns the numeric group id of the owner of stat.
-
#grpowned? ⇒ Boolean
Returns true if the effective group id of the process is the same as the group id of stat.
-
#File::Stat.new(file_name) ⇒ Object
constructor
Create a File::Stat object for the given file name (raising an exception if the file doesn’t exist).
-
#initialize_copy ⇒ Object
:nodoc:.
-
#ino ⇒ Fixnum
Returns the inode number for stat.
-
#inspect ⇒ String
Produce a nicely formatted description of stat.
-
#mode ⇒ Fixnum
Returns an integer representing the permission bits of stat.
-
#mtime ⇒ aTime
Returns the modification time of stat.
-
#nlink ⇒ Fixnum
Returns the number of hard links to stat.
-
#owned? ⇒ Boolean
Returns
true
if the effective user id of the process is the same as the owner of stat. -
#pipe? ⇒ Boolean
Returns
true
if the operating system supports pipes and stat is a pipe;false
otherwise. -
#rdev ⇒ Fixnum?
Returns an integer representing the device type on which stat resides.
-
#rdev_major ⇒ Fixnum
Returns the major part of
File_Stat#rdev
ornil
. -
#rdev_minor ⇒ Fixnum
Returns the minor part of
File_Stat#rdev
ornil
. -
#readable? ⇒ Boolean
Returns
true
if stat is readable by the effective user id of this process. -
#readable_real? ⇒ Boolean
Returns
true
if stat is readable by the real user id of this process. -
#setgid? ⇒ Boolean
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. -
#setuid? ⇒ Boolean
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. -
#size ⇒ Fixnum
Returns the size of stat in bytes.
-
#size ⇒ Integer
Returns the size of stat in bytes.
-
#socket? ⇒ Boolean
Returns
true
if stat is a socket,false
if it isn’t or if the operating system doesn’t support this feature. -
#sticky? ⇒ Boolean
Returns
true
if stat has its sticky bit set,false
if it doesn’t or if the operating system doesn’t support this feature. -
#symlink? ⇒ Boolean
Returns
true
if stat is a symbolic link,false
if it isn’t or if the operating system doesn’t support this feature. -
#uid ⇒ Fixnum
Returns the numeric user id of the owner of stat.
-
#writable? ⇒ Boolean
Returns
true
if stat is writable by the effective user id of this process. -
#writable_real? ⇒ Boolean
Returns
true
if stat is writable by the real user id of this process. -
#zero? ⇒ Boolean
Returns
true
if stat is a zero-length file;false
otherwise.
Methods included from Comparable
#<, #<=, #==, #>, #>=, #between?
Constructor Details
#File::Stat.new(file_name) ⇒ Object
Create a File::Stat object for the given file name (raising an exception if the file doesn’t exist).
3502 3503 3504 |
# File 'file.c', line 3502 static VALUE rb_stat_init(obj, fname) VALUE obj, fname; |
Instance Method Details
#<=>(other_stat) ⇒ -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
193 194 195 |
# File 'file.c', line 193 static VALUE rb_stat_cmp(self, other) VALUE self, other; |
#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
529 530 531 |
# File 'file.c', line 529 static VALUE rb_stat_atime(self) VALUE self; |
#blksize ⇒ Integer?
Returns the native file system’s block size. Will return nil
on platforms that don’t support this information.
File.stat("testfile").blksize #=> 4096
484 485 486 |
# File 'file.c', line 484 static VALUE rb_stat_blksize(self) VALUE self; |
#blockdev? ⇒ Boolean
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
3672 3673 3674 |
# File 'file.c', line 3672 static VALUE rb_stat_b(obj) VALUE obj; |
#blocks ⇒ Integer?
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
506 507 508 |
# File 'file.c', line 506 static VALUE rb_stat_blocks(self) VALUE self; |
#chardev? ⇒ Boolean
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
3695 3696 3697 |
# File 'file.c', line 3695 static VALUE rb_stat_c(obj) VALUE obj; |
#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
565 566 567 |
# File 'file.c', line 565 static VALUE rb_stat_ctime(self) VALUE self; |
#dev ⇒ Fixnum
Returns an integer representing the device on which stat resides.
File.stat("testfile").dev #=> 774
234 235 236 |
# File 'file.c', line 234 static VALUE rb_stat_dev(self) VALUE self; |
#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
252 253 254 |
# File 'file.c', line 252 static VALUE rb_stat_dev_major(self) VALUE self; |
#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
275 276 277 |
# File 'file.c', line 275 static VALUE rb_stat_dev_minor(self) VALUE self; |
#directory? ⇒ Boolean
Returns true
if stat is a directory, false
otherwise.
File.stat("testfile").directory? #=> false
File.stat(".").directory? #=> true
3582 3583 3584 |
# File 'file.c', line 3582 static VALUE rb_stat_d(obj) VALUE obj; |
#executable? ⇒ Boolean
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
3905 3906 3907 |
# File 'file.c', line 3905 static VALUE rb_stat_x(obj) VALUE obj; |
#executable_real? ⇒ Boolean
Same as executable?
, but tests using the real owner of the process.
3939 3940 3941 |
# File 'file.c', line 3939 static VALUE rb_stat_X(obj) VALUE obj; |
#file? ⇒ Boolean
Returns true
if stat is a regular file (not a device file, pipe, socket, etc.).
File.stat("testfile").file? #=> true
3975 3976 3977 |
# File 'file.c', line 3975 static VALUE rb_stat_f(obj) VALUE obj; |
#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"
3564 3565 3566 |
# File 'file.c', line 3564 static VALUE rb_stat_ftype(obj) VALUE obj; |
#gid ⇒ Fixnum
Returns the numeric group id of the owner of stat.
File.stat("testfile").gid #=> 500
380 381 382 |
# File 'file.c', line 380 static VALUE rb_stat_gid(self) VALUE self; |
#grpowned? ⇒ Boolean
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
3744 3745 3746 |
# File 'file.c', line 3744 static VALUE rb_stat_grpowned(obj) VALUE obj; |
#initialize_copy ⇒ Object
:nodoc:
3525 3526 3527 |
# File 'file.c', line 3525 static VALUE rb_stat_init_copy(copy, orig) VALUE copy, orig; |
#ino ⇒ Fixnum
Returns the inode number for stat.
File.stat("testfile").ino #=> 1083669
298 299 300 |
# File 'file.c', line 298 static VALUE rb_stat_ino(self) VALUE self; |
#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>"
586 587 588 |
# File 'file.c', line 586 static VALUE rb_stat_inspect(self) VALUE self; |
#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"
322 323 324 |
# File 'file.c', line 322 static VALUE rb_stat_mode(self) VALUE self; |
#mtime ⇒ aTime
Returns the modification time of stat.
File.stat("testfile").mtime #=> Wed Apr 09 08:53:14 CDT 2003
546 547 548 |
# File 'file.c', line 546 static VALUE rb_stat_mtime(self) VALUE self; |
#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
345 346 347 |
# File 'file.c', line 345 static VALUE rb_stat_nlink(self) VALUE self; |
#owned? ⇒ Boolean
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
3716 3717 3718 |
# File 'file.c', line 3716 static VALUE rb_stat_owned(obj) VALUE obj; |
#pipe? ⇒ Boolean
Returns true
if the operating system supports pipes and stat is a pipe; false
otherwise.
3598 3599 3600 |
# File 'file.c', line 3598 static VALUE rb_stat_p(obj) VALUE obj; |
#rdev ⇒ Fixnum?
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
400 401 402 |
# File 'file.c', line 400 static VALUE rb_stat_rdev(self) VALUE self; |
#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
422 423 424 |
# File 'file.c', line 422 static VALUE rb_stat_rdev_major(self) VALUE self; |
#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
445 446 447 |
# File 'file.c', line 445 static VALUE rb_stat_rdev_minor(self) VALUE self; |
#readable? ⇒ Boolean
Returns true
if stat is readable by the effective user id of this process.
File.stat("testfile").readable? #=> true
3765 3766 3767 |
# File 'file.c', line 3765 static VALUE rb_stat_r(obj) VALUE obj; |
#readable_real? ⇒ Boolean
Returns true
if stat is readable by the real user id of this process.
File.stat("testfile").readable_real? #=> true
3801 3802 3803 |
# File 'file.c', line 3801 static VALUE rb_stat_R(obj) VALUE obj; |
#setgid? ⇒ Boolean
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
4056 4057 4058 |
# File 'file.c', line 4056 static VALUE rb_stat_sgid(obj) VALUE obj; |
#setuid? ⇒ Boolean
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
4034 4035 4036 |
# File 'file.c', line 4034 static VALUE rb_stat_suid(obj) VALUE obj; |
#size ⇒ Fixnum
Returns the size of stat in bytes.
File.stat("testfile").size #=> 66
466 467 468 |
# File 'file.c', line 466 static VALUE rb_stat_size(self) VALUE self; |
#size ⇒ Integer
Returns the size of stat in bytes.
File.stat("testfile").size #=> 66
4013 4014 4015 |
# File 'file.c', line 4013 static VALUE rb_stat_s(obj) VALUE obj; |
#socket? ⇒ Boolean
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
3648 3649 3650 |
# File 'file.c', line 3648 static VALUE rb_stat_S(obj) VALUE obj; |
#sticky? ⇒ Boolean
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
4078 4079 4080 |
# File 'file.c', line 4078 static VALUE rb_stat_sticky(obj) VALUE obj; |
#symlink? ⇒ Boolean
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
3626 3627 3628 |
# File 'file.c', line 3626 static VALUE rb_stat_l(obj) VALUE obj; |
#uid ⇒ Fixnum
Returns the numeric user id of the owner of stat.
File.stat("testfile").uid #=> 501
363 364 365 |
# File 'file.c', line 363 static VALUE rb_stat_uid(self) VALUE self; |
#writable? ⇒ Boolean
Returns true
if stat is writable by the effective user id of this process.
File.stat("testfile").writable? #=> true
3835 3836 3837 |
# File 'file.c', line 3835 static VALUE rb_stat_w(obj) VALUE obj; |
#writable_real? ⇒ Boolean
Returns true
if stat is writable by the real user id of this process.
File.stat("testfile").writable_real? #=> true
3869 3870 3871 |
# File 'file.c', line 3869 static VALUE rb_stat_W(obj) VALUE obj; |
#zero? ⇒ Boolean
Returns true
if stat is a zero-length file; false
otherwise.
File.stat("testfile").zero? #=> false
3994 3995 3996 |
# File 'file.c', line 3994 static VALUE rb_stat_z(obj) VALUE obj; |