Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
File::Stat#ftype
() -> ::File::ftype
ftype → string
file.c
View on GitHub ↗
static VALUE
rb_stat_ftype(VALUE obj)
{
return rb_file_ftype(get_stat(obj)->ST_(mode));
}
Returns the string type of the path in the snapshot in self, one of:
-
'file'. -
'directory'. -
'characterSpecial'. -
'blockSpecial'. -
'fifo'. -
'link'. -
'socket'.
Examples:
Example
File.stat('/etc/passwd').ftype # => "file" File.stat('/etc').ftype # => "directory" File.stat('/dev/null').ftype # => "characterSpecial" File.stat('/dev/loop0').ftype # => "blockSpecial" File.mkfifo('/tmp/pipe', 0o666) File.stat('/tmp/pipe').ftype # => "fifo" File.symlink('/etc/passwd', '/tmp/link') File.lstat('/tmp/link').ftype # => "link" require 'socket' UNIXServer.new('/tmp/socket') File.stat('/tmp/socket').ftype # => "socket" File.delete('/tmp/link', '/tmp/pipe', '/tmp/socket') # Clean up.
Returns 'unknown' if the type cannot be determined.