Reason #141 • May 21st, 2026

Checking if a file exists

Ruby
File.exist?("path/to/file.txt")
# => true or false
    

What's not to love?

History

File.exist? was added in Ruby 1.4, released in 1999, but it existed as FileTest.exist? before then, all the way from Ruby's inception (and still does).

Curiously, it also had an exists? alias all the way up until Ruby 3.2, when this alias was finally removed in favour of only supporting the shorter variant.

In Crystal, the equivalent method is instead locked down to File.exists?, which might read more naturally to some.