Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby keeps telling me my file does not exist

I'm trying to check if a file exists with RoR but it keeps saying this file does not exist and I can't understand why.

if File.exist?('~/Desktop/test.xls')
  p 'File EXISTS'
else
  p 'Cannot find any file'
end

Of course the file exists and I can access it with the terminal using 'ls'.

The script is into the scripts folder of my rails app.

Thanks for any help

like image 832
El-Cortez Avatar asked Sep 18 '26 07:09

El-Cortez


1 Answers

It should be something like this:

if File.exist?("#{Dir.home}/Desktop/test.xls")
  p 'File EXISTS'
else
  p 'Cannot find any file'
end

where Dir.home is your particular home directory (in my case it is /Users/m.pontyushenko/)

like image 95
Maxim Pontyushenko Avatar answered Sep 19 '26 21:09

Maxim Pontyushenko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!