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).
3664 3665 3666 |
# File 'file.c', line 3664 static VALUE rb_stat_init(obj, fname) VALUE obj, fname; |
Instance Method Details
#<=>(other_stat) ⇒ -1, ...
197 198 199 |
# File 'file.c', line 197 static VALUE rb_stat_cmp(self, other) VALUE self, other; |
#blksize ⇒ Integer?
488 489 490 |
# File 'file.c', line 488 static VALUE rb_stat_blksize(self) VALUE self; |
#blockdev? ⇒ Boolean
3834 3835 3836 |
# File 'file.c', line 3834 static VALUE rb_stat_b(obj) VALUE obj; |
#blocks ⇒ Integer?
510 511 512 |
# File 'file.c', line 510 static VALUE rb_stat_blocks(self) VALUE self; |
#chardev? ⇒ Boolean
3857 3858 3859 |
# File 'file.c', line 3857 static VALUE rb_stat_c(obj) VALUE obj; |
#ctime ⇒ aTime
569 570 571 |
# File 'file.c', line 569 static VALUE rb_stat_ctime(self) VALUE self; |
#dev ⇒ Fixnum
238 239 240 |
# File 'file.c', line 238 static VALUE rb_stat_dev(self) VALUE self; |
#dev_major ⇒ Fixnum
256 257 258 |
# File 'file.c', line 256 static VALUE rb_stat_dev_major(self) VALUE self; |
#dev_minor ⇒ Fixnum
279 280 281 |
# File 'file.c', line 279 static VALUE rb_stat_dev_minor(self) VALUE self; |
#directory? ⇒ Boolean
3744 3745 3746 |
# File 'file.c', line 3744 static VALUE rb_stat_d(obj) VALUE obj; |
#executable? ⇒ Boolean
4067 4068 4069 |
# File 'file.c', line 4067 static VALUE rb_stat_x(obj) VALUE obj; |
#executable_real? ⇒ Boolean
Same as executable?
, but tests using the real owner of the process.
4101 4102 4103 |
# File 'file.c', line 4101 static VALUE rb_stat_X(obj) VALUE obj; |
#file? ⇒ Boolean
4137 4138 4139 |
# File 'file.c', line 4137 static VALUE rb_stat_f(obj) VALUE obj; |
#ftype ⇒ String
3726 3727 3728 |
# File 'file.c', line 3726 static VALUE rb_stat_ftype(obj) VALUE obj; |
#gid ⇒ Fixnum
384 385 386 |
# File 'file.c', line 384 static VALUE rb_stat_gid(self) VALUE self; |
#grpowned? ⇒ Boolean
3906 3907 3908 |
# File 'file.c', line 3906 static VALUE rb_stat_grpowned(obj) VALUE obj; |
#initialize_copy ⇒ Object
:nodoc:
3687 3688 3689 |
# File 'file.c', line 3687 static VALUE rb_stat_init_copy(copy, orig) VALUE copy, orig; |
#ino ⇒ Fixnum
302 303 304 |
# File 'file.c', line 302 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>"
590 591 592 |
# File 'file.c', line 590 static VALUE rb_stat_inspect(self) VALUE self; |
#mtime ⇒ aTime
550 551 552 |
# File 'file.c', line 550 static VALUE rb_stat_mtime(self) VALUE self; |
#owned? ⇒ Boolean
3878 3879 3880 |
# File 'file.c', line 3878 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.
3760 3761 3762 |
# File 'file.c', line 3760 static VALUE rb_stat_p(obj) VALUE obj; |
#rdev_major ⇒ Fixnum
426 427 428 |
# File 'file.c', line 426 static VALUE rb_stat_rdev_major(self) VALUE self; |
#rdev_minor ⇒ Fixnum
449 450 451 |
# File 'file.c', line 449 static VALUE rb_stat_rdev_minor(self) VALUE self; |
#readable? ⇒ Boolean
3927 3928 3929 |
# File 'file.c', line 3927 static VALUE rb_stat_r(obj) VALUE obj; |
#readable_real? ⇒ Boolean
3963 3964 3965 |
# File 'file.c', line 3963 static VALUE rb_stat_R(obj) VALUE obj; |
#setgid? ⇒ Boolean
4218 4219 4220 |
# File 'file.c', line 4218 static VALUE rb_stat_sgid(obj) VALUE obj; |
#setuid? ⇒ Boolean
4196 4197 4198 |
# File 'file.c', line 4196 static VALUE rb_stat_suid(obj) VALUE obj; |
#size ⇒ Fixnum
470 471 472 |
# File 'file.c', line 470 static VALUE rb_stat_size(self) VALUE self; |
#size ⇒ Integer
4175 4176 4177 |
# File 'file.c', line 4175 static VALUE rb_stat_s(obj) VALUE obj; |
#socket? ⇒ Boolean
3810 3811 3812 |
# File 'file.c', line 3810 static VALUE rb_stat_S(obj) VALUE obj; |
#sticky? ⇒ Boolean
4240 4241 4242 |
# File 'file.c', line 4240 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
3788 3789 3790 |
# File 'file.c', line 3788 static VALUE rb_stat_l(obj) VALUE obj; |
#uid ⇒ Fixnum
367 368 369 |
# File 'file.c', line 367 static VALUE rb_stat_uid(self) VALUE self; |
#writable? ⇒ Boolean
3997 3998 3999 |
# File 'file.c', line 3997 static VALUE rb_stat_w(obj) VALUE obj; |
#writable_real? ⇒ Boolean
4031 4032 4033 |
# File 'file.c', line 4031 static VALUE rb_stat_W(obj) VALUE obj; |