From: Daniel Frank Date: 2010-03-30T06:50:12+09:00 Subject: Re: Ruby cannot find the file in the directory - Error Enoent Sask Khan wrote: > Roger Pack wrote: >> You'll need to run "ruby" from the same directory where 'text.txt' is >> located. >> -rp > > Roger, what do you mean? Ruby.exe is sitting in C:\Program > Files\Ruby\Bin\ruby.exe, am I to copy the script and the txt file to > that folder in order to run this? No. Add the following line on the top of your script: Dir.pwd This will show you in which working directory ruby was started from. Guessing from the screenshot I assume it will be C:\Program Files\Notepad++. Since you did not specify the path of test.txt, ruby will try to open a file test.txt in that directory. There are a couple of ways around: a) Change the working directory before you start ruby. For example open a command prompt, enter "cd /d g:\docs\l_ruby", then run the script: "ruby analyzer.rb" b) Change the working directory after you start ruby. Add a line before your "File.read...." line: Dir.chdir("g:/docs/l_ruby") That will change the working directory to the one that contains the test.txt file. c) Figure out how to change the working directory that Notepad++ starts ruby in. I have no idea how to do this. I hope this will get you back on the track again. I suggest you have a look at http://en.wikipedia.org/wiki/Working_directory to learn what a working directory is, if you don't know already. It's essential to know when writing scripts. -- Posted via http://www.ruby-forum.com/.