3

I think I am doing this all wrong but if I am in directory foo/ which is a child of bar/ and I do:

File.exists?(../somefile.rb)

it returns false, when it should be true ... unless I am doing it wrong:

bar/
  somefile.rb
  foo/
    someotherfile.rb

someotherfile.rb is the one with the code to check if somefile.rb exists.

What am I doing wrong - I am trying to see if it exists, so I can open it.

user3379926
  • 3,855
  • 6
  • 24
  • 42
  • 2
    It works fine here, please make sure the directory structure is indeed what you say it is. Also, make sure you did not change your working directory. `Dir.getwd` will return the current working directory so make sure that's indeed `bar/foo` in your case. – Daniël Knippers Apr 13 '14 at 17:03
  • 1
    `File.exists?` is actually deprecated in ruby 2.1 - Use `File.exist?` instead – Musannif Zahir Apr 13 '14 at 17:25

1 Answers1

1

If the process does not have permissions to tell whether a file exists it will return false. It may be possible to open a file, but not tell by normal methods if it exists.

source:- File.exists() returns false when file exists

Community
  • 1
  • 1
Saurabh
  • 71,488
  • 40
  • 181
  • 244
  • The source you list is for java, not ruby. While the same issues dealing with Windows OS may apply, seeing that syntax on your source page freaked me out until I realized they were discussing java. – Perry Tew May 03 '16 at 11:44