title: Ruby: File not found exception, even though it exists, and is passed down by loop
body: <p>I'm practicing Ruby after growing to resent Java with a simple little program that determines how similar a few thousand documents are. I did the same thing in Java junior year of high school for a data structures project, and actually wrote the fastest program the teacher had ever seen (apparently), but somehow I can't transfer that over to Ruby.</p>
  
  <p>I'm trying to create an array of files:</p>
  
  <pre><code>array = Dir.foreach("/home/rj/Documents/Ruby Code/Catching Plaigarists/Large number of documents") do |filename|
      File.new(filename, "r") unless filename.start_with?(".") #Prevents it from returning current and parent directories
  end
  </code></pre>
  
  <p>When I run it in the terminal, I get this rather irritating exception:</p>
  
  <pre><code>/home/rj/Documents/Ruby Code/Catching Plaigarists/y_don_it_work.rb:2:in `initialize': No such file or directory @ rb_sysopen - bmu390.shtml.txt (Errno::ENOENT)
      from /home/rj/Documents/Ruby Code/Catching Plaigarists/y_don_it_work.rb:2:in `new'
      from /home/rj/Documents/Ruby Code/Catching Plaigarists/y_don_it_work.rb:2:in `block in &lt;main&gt;'
      from /home/rj/Documents/Ruby Code/Catching Plaigarists/y_don_it_work.rb:1:in `foreach'
      from /home/rj/Documents/Ruby Code/Catching Plaigarists/y_don_it_work.rb:1:in `&lt;main&gt;'
  </code></pre>
  
  <p>I checked to make sure the document existed. It did. Ran it again a few more times. Same thing with the same document. Naturally, I tried deleting the document. But then it did the same thing for some other document. And when I deleted that document, it managed to find some problem with some other document with <em>a higher alphabetical precedence</em> that it seemed to do just fine with the first two times around.</p>
  
  <p>Why can't it find these documents, and if they don't exist, why does the loop pass the filenames down in the first place? What am I doing wrong? Why me?</p>
  
  <p>(Also I'm running Fedora with Cinnamon, if that would have any impact.)</p>