Skip to content

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

class method

File.ftype

(::path file_name) -> ::String
File.ftype(path) → string

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

  • 'file'.

  • 'directory'.

  • 'characterSpecial'.

  • 'blockSpecial'.

  • 'fifo'.

  • 'link'.

  • 'socket'.

Examples:

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

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

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

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

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

Returns 'unknown' if the type cannot be determined.

See also .fnmatch? .grpowned? .fnmatch .identical? also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0