From: Josh Cheek Date: 2011-04-11T17:51:30+09:00 Subject: Re: File.open very basic --bcaec547c9936212b304a0a0ae59 Content-Type: text/plain; charset=ISO-8859-1 Maybe your text editor doesn't run it from the same location the files are stored in. When you say to open "text.txt" it is looking in your current directory, Dir.pwd, not the current directory of the file File.dirname(__FILE__). ~/deleteme/file-test $ tree . |-- linecounter | |-- linecount.rb | `-- text.txt `-- text.txt 1 directory, 3 files ~/deleteme/file-test $ cd linecounter/ ~/deleteme/file-test/linecounter $ ruby linecount.rb 5 ~/deleteme/file-test/linecounter $ cat text.txt 1 2 3 4 5 ~/deleteme/file-test/linecounter $ cd .. ~/deleteme/file-test $ ruby linecounter/linecount.rb 3 ~/deleteme/file-test $ cat text.txt 1 2 3 ~/deleteme/file-test $ rm text.txt ~/deleteme/file-test $ ruby linecounter/linecount.rb linecounter/linecount.rb:2:in `initialize': No such file or directory - text.txt (Errno::ENOENT) from linecounter/linecount.rb:2:in `open' from linecounter/linecount.rb:2:in `
' ~/deleteme/file-test $ tree . `-- linecounter |-- linecount.rb `-- text.txt --bcaec547c9936212b304a0a0ae59--