Class: File::Stat
- Inherits:
- NSObject show all
- Includes:
- Comparable
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.
Class Method Summary (collapse)
-
+ alloc
Objects of class File::Stat encapsulate common status information for File objects.
Instance Method Summary (collapse)
-
- <=>
Compares File::Stat objects by comparing their respective modification times.
-
- atime
Returns the last access time for this file as an object of class Time.
-
- blksize
Returns the native file system's block size.
-
- blockdev?
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
Returns the number of native file system blocks allocated for this file, or nil if the operating system doesn't support this feature.
-
- chardev?
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
Returns the change time for stat (that is, the time directory information about the file was changed, not the file itself).
-
- dev
Returns an integer representing the device on which stat resides.
-
- dev_major
Returns the major part of File_Stat#dev or nil.
-
- dev_minor
Returns the minor part of File_Stat#dev or nil.
-
- directory?
Returns true if stat is a directory, false otherwise.
-
- executable?
Returns true if stat is executable or if the operating system doesn't distinguish executable files from nonexecutable files.
-
- executable_real?
Same as executable?, but tests using the real owner of the process.
-
- file?
Returns true if stat is a regular file (not a device file, pipe, socket, etc.).
-
- ftype
Identifies the type of stat.
-
- gid
Returns the numeric group id of the owner of stat.
-
- grpowned?
Returns true if the effective group id of the process is the same as the group id of stat.
-
- File::Stat.new
constructor
Create a File::Stat object for the given file name (raising an exception if the file doesn't exist).
-
- initialize_copy
:nodoc:.
-
- ino
Returns the inode number for stat.
-
- inspect
Produce a nicely formatted description of stat.
-
- mode
Returns an integer representing the permission bits of stat.
-
- mtime
Returns the modification time of stat.
-
- nlink
Returns the number of hard links to stat.
-
- owned?
Returns true if the effective user id of the process is the same as the owner of stat.
-
- pipe?
Returns true if the operating system supports pipes and stat is a pipe; false otherwise.
-
- rdev
Returns an integer representing the device type on which stat resides.
-
- rdev_major
Returns the major part of File_Stat#rdev or nil.
-
- rdev_minor
Returns the minor part of File_Stat#rdev or nil.
-
- readable?
Returns true if stat is readable by the effective user id of this process.
-
- readable_real?
Returns true if stat is readable by the real user id of this process.
-
- setgid?
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?
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
Returns the size of stat in bytes.
-
- size
Returns the size of stat in bytes.
-
- socket?
Returns true if stat is a socket, false if it isn't or if the operating system doesn't support this feature.
-
- sticky?
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?
Returns true if stat is a symbolic link, false if it isn't or if the operating system doesn't support this feature.
-
- uid
Returns the numeric user id of the owner of stat.
-
- world_readable?
If stat is readable by others, returns an integer representing the file permission bits of stat.
-
- world_writable?
If stat is writable by others, returns an integer representing the file permission bits of stat.
-
- writable?
Returns true if stat is writable by the effective user id of this process.
-
- writable_real?
Returns true if stat is writable by the real user id of this process.
-
- zero?
Returns true if stat is a zero-length file; false otherwise.
Methods included from Comparable
#<, #<=, #==, #>, #>=, #between?
Methods inherited from NSObject
#!, #!=, #!~, #==, #===, #=~, #Rational, #__callee__, #__method__, #__send__, #__type__, `, allocWithZone:, #autoContentAccessingProxy, autoload, autoload?, autorelease_pool, #awakeAfterUsingCoder:, binding, block_given?, caller, cancelPreviousPerformRequestsWithTarget:, cancelPreviousPerformRequestsWithTarget:selector:object:, catch, class, classFallbacksForKeyedArchiver, #classForCoder, #classForKeyedArchiver, classForKeyedUnarchiver, #clone, conformsToProtocol:, #copy, copyWithZone:, #dealloc, #define_singleton_method, description, display, #doesNotRecognizeSelector:, #dup, #enum_for, #eql?, #equal?, #extend, fail, #finalize, format, #forwardInvocation:, #forwardingTargetForSelector:, framework, #freeze, #frozen?, getpass, gets, global_variables, #init, initialize, #initialize_clone, #initialize_dup, instanceMethodForSelector:, instanceMethodSignatureForSelector:, #instance_eval, #instance_exec, #instance_of?, #instance_variable_defined?, #instance_variable_get, #instance_variable_set, #instance_variables, instancesRespondToSelector:, isSubclassOfClass:, #is_a?, iterator?, #kind_of?, lambda, load, load_bridge_support_file, load_plist, local_variables, loop, #method, #methodForSelector:, #methodSignatureForSelector:, #methods, #mutableCopy, mutableCopyWithZone:, new, #nil?, open, p, #performSelector:onThread:withObject:waitUntilDone:, #performSelector:onThread:withObject:waitUntilDone:modes:, #performSelector:withObject:afterDelay:, #performSelector:withObject:afterDelay:inModes:, #performSelectorInBackground:withObject:, #performSelectorOnMainThread:withObject:waitUntilDone:, #performSelectorOnMainThread:withObject:waitUntilDone:modes:, print, printf, #private_methods, proc, #protected_methods, #public_method, #public_methods, #public_send, putc, puts, raise, rand, readline, readlines, #replacementObjectForCoder:, #replacementObjectForKeyedArchiver:, require, resolveClassMethod:, resolveInstanceMethod:, #respond_to?, #respond_to_missing?, select, #send, setVersion:, #singleton_methods, sprintf, srand, superclass, #taint, #tainted?, #tap, test, throw, #to_plist, #to_s, trace_var, trap, #trust, #untaint, untrace_var, #untrust, #untrusted?, version
Constructor Details
- (File::Stat) File(file_name)
Create a File::Stat object for the given file name (raising an exception if the file doesn't exist).
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class NSObject
Class Method Details
+ (Object) alloc
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 Details
- (-1, ...) <=>(other_stat)
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
- (Time) atime
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
- (Integer?) blksize
Returns the native file system's block size. Will return nil on platforms that don't support this information.
File.stat("testfile").blksize #=> 4096
- (Boolean) blockdev?
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
- (Integer?) blocks
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
- (Boolean) chardev?
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
- (Time) ctime
Returns the change time for stat (that is, the time directory information about the file was changed, not the file itself).
Note that on Windows (NTFS), returns creation time (birth time).
File.stat("testfile").ctime #=> Wed Apr 09 08:53:14 CDT 2003
- (Fixnum) dev
Returns an integer representing the device on which stat resides.
File.stat("testfile").dev #=> 774
- (Fixnum) dev_major
Returns the major part of File_Stat#dev or nil.
File.stat("/dev/fd1").dev_major #=> 2
File.stat("/dev/tty").dev_major #=> 5
- (Fixnum) dev_minor
Returns the minor part of File_Stat#dev or nil.
File.stat("/dev/fd1").dev_minor #=> 1
File.stat("/dev/tty").dev_minor #=> 0
- (Boolean) directory?
Returns true if stat is a directory, false otherwise.
File.stat("testfile").directory? #=> false
File.stat(".").directory? #=> true
- (Boolean) executable?
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
- (Boolean) executable_real?
Same as executable?, but tests using the real owner of the process.
- (Boolean) file?
Returns true if stat is a regular file (not a device file, pipe, socket, etc.).
File.stat("testfile").file? #=> true
- (String) ftype
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"
- (Fixnum) gid
Returns the numeric group id of the owner of stat.
File.stat("testfile").gid #=> 500
- (Boolean) grpowned?
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
- (Object) initialize_copy
:nodoc:
- (Fixnum) ino
Returns the inode number for stat.
File.stat("testfile").ino #=> 1083669
- (String) inspect
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>"
- (Fixnum) mode
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"
- (Time) mtime
Returns the modification time of stat.
File.stat("testfile").mtime #=> Wed Apr 09 08:53:14 CDT 2003
- (Fixnum) nlink
Returns the number of hard links to stat.
File.stat("testfile").nlink #=> 1
File.link("testfile", "testfile.bak") #=> 0
File.stat("testfile").nlink #=> 2
- (Boolean) owned?
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
- (Boolean) pipe?
Returns true if the operating system supports pipes and stat is a pipe; false otherwise.
- (Fixnum?) rdev
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
- (Fixnum) rdev_major
Returns the major part of File_Stat#rdev or nil.
File.stat("/dev/fd1").rdev_major #=> 2
File.stat("/dev/tty").rdev_major #=> 5
- (Fixnum) rdev_minor
Returns the minor part of File_Stat#rdev or nil.
File.stat("/dev/fd1").rdev_minor #=> 1
File.stat("/dev/tty").rdev_minor #=> 0
- (Boolean) readable?
Returns true if stat is readable by the effective user id of this process.
File.stat("testfile").readable? #=> true
- (Boolean) readable_real?
Returns true if stat is readable by the real user id of this process.
File.stat("testfile").readable_real? #=> true
- (Boolean) setgid?
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
- (Boolean) setuid?
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
- (Fixnum) size
Returns the size of stat in bytes.
File.stat("testfile").size #=> 66
- (Integer) size
Returns the size of stat in bytes.
File.stat("testfile").size #=> 66
- (Boolean) socket?
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
- (Boolean) sticky?
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
- (Boolean) symlink?
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
- (Fixnum) uid
Returns the numeric user id of the owner of stat.
File.stat("testfile").uid #=> 501
- (Fixnum?) world_readable?
If stat is readable by others, returns an integer representing the file permission bits of stat. Returns nil otherwise. The meaning of the bits is platform dependent; on Unix systems, see stat(2).
m = File.stat("/etc/passwd").world_readable? #=> 420
sprintf("%o", m) #=> "644"
- (Fixnum?) world_writable?
If stat is writable by others, returns an integer representing the file permission bits of stat. Returns nil otherwise. The meaning of the bits is platform dependent; on Unix systems, see stat(2).
m = File.stat("/tmp").world_writable? #=> 511
sprintf("%o", m) #=> "777"
- (Boolean) writable?
Returns true if stat is writable by the effective user id of this process.
File.stat("testfile").writable? #=> true
- (Boolean) writable_real?
Returns true if stat is writable by the real user id of this process.
File.stat("testfile").writable_real? #=> true
- (Boolean) zero?
Returns true if stat is a zero-length file; false otherwise.
File.stat("testfile").zero? #=> false