On Sun, Dec 7, 2008 at 12:46 PM, Stuart Clarke <stuart.clarke1986 / gmail.com> wrote: > I am trying to read keywords and phrases from a .txt file and run these > words against a given directory structure. I seem to be having a few > problems, when I run my code i get the following error: > > C:\Documents and Settings\user\Desktop>keywordsearch.rb "C:\Documents > and Sett > ings\user" > C:/Documents and Settings/user/Desktop/keywordsearch.rb:21:in > `initialize': No > such file or directory - C:\Documents and > Settings\user\Desktop\terms.txt (Er > rno::ENOENT) > > I cannot see what is wrong with my code see below: > > File.open(curPath) do |file| > file.each do |line| > o = File.open("C:\\Documents and > Settings\\user\\Desktop\\terms.txt") > terms = o.readlines > terms.each do |term| > if line =~ term > puts "#{curPath}" > end > end > o.close > end > end > > Any ideas, I really appreciate the guidance. > > Regards > -- > Posted via http://www.ruby-forum.com/. > > I am not sure \\ works, try simple /. And I am sure the file exists and is readable. Another topic instead of o = File.open ... o.close you might prefer File.open do |o| ... end which will assure o is closed *even* if an exception is raised in your block. HTH R. -- Il computer non una macchina intelligente che aiuta le persone stupide, anzi, una macchina stupida che funziona solo nelle mani delle persone intelligenti. Computers are not smart to help stupid people, rather they are stupid and will work only if taken care of by smart people. Umberto Eco