How to check for file existence [duplicate]
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?
# file? will only return true for files
File.file?(filename)
and
# Will also return true for directories - watch out!
File.exist?(filename)
Check out Pathname and in particular Pathname#exist?
.
File and its FileTest module are perhaps simpler/more direct, but I find Pathname
a nicer interface in general.