Checking if a file exists in the user's home directory Checking if a file exists in the user's home directory ruby ruby

Checking if a file exists in the user's home directory


A call to Dir.home is a OS independent way to get to the home directory for the user. You can then use it like

File.exists?(File.join(Dir.home, ".my_proj_config"))


This works in Ruby 1.9, but note that the call to expand_path is required on some systems (e.g. Windows):

File.exists?( File.expand_path "~/.my_proj_config" )


Use the class File and its method exist?.