How to check for file existence

iwan picture iwan · Dec 21, 2011 · Viewed 206k times · Source

Is there a Ruby class/method where I could pass "a full path", home/me/a_file.txt, to identify whether it is a valid file path?

Answer

zed_0xff picture zed_0xff · Dec 21, 2011
# file? will only return true for files
File.file?(filename)

and

# Will also return true for directories - watch out!
File.exist?(filename)