Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

Pathname#ftype

() -> ::String
ftype → string

Returns the string type of the object at the path in self, one of:

  • 'file'.

  • 'directory'.

  • 'characterSpecial'.

  • 'blockSpecial'.

  • 'fifo'.

  • 'link'.

  • 'socket'.

Examples:

Example
Pathname('/etc/passwd').ftype # => "file"
Pathname('/etc').ftype        # => "directory"
Pathname('/dev/null').ftype   # => "characterSpecial"
Pathname('/dev/loop0').ftype  # => "blockSpecial"

File.mkfifo('/tmp/pipe', 0o666)
Pathname('/tmp/pipe').ftype   # => "fifo"

File.symlink('/etc/passwd', '/tmp/link')
Pathname('/tmp/link').ftype   # => "link"

require 'socket'
UNIXServer.new('/tmp/socket')
Pathname('/tmp/socket').ftype # => "socket"

File.delete('/tmp/link', '/tmp/pipe', '/tmp/socket') # Clean up.

Returns 'unknown' if the type cannot be determined.

See also #freeze #glob #fnmatch? #grpowned? also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0