Skip to content

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

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.

See also #file? #gid #executable_real? #grpowned? also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0