What is File.ftype() in Ruby?

Overview

We use the ftype() function of a File class in Ruby to identify the type of a file. It returns the string file, directory, characterSpecial, blockSpecial, fifo, link, socket, or unknown.

Syntax

File.ftype(file_name)

Parameter

file_name: This is the file name whose file type we want to get.

Return value

The string returns the string file, directory, characterSpecial, blockSpecial, fifo, link, socket, or unknown.

Code example

main.rb
hmm.tty
hmm.X0
app.js

Explanation

We create some files and our application code main.rb.

  • Line 2-5: We get the file names.
  • Line 8-11: We print the name types of the file to the console.

Free Resources