From: Brad Winborg Date: 2009-03-02T11:28:49+09:00 Subject: Re: Error when running script Tim Greer wrote: > Brad Winborg wrote: > >>>> D:\My Documents\Replicon >> >> puts my_path + fl >> puts warning.to_s >> Press ENTER to close the window... >> > > That code should work. Are you sure that the text file's content > actually match "error" or "warning"? Did you check the letter case? > Perhaps try and put a "puts line" right after the open and see what it > outputs. It looks to be reading the files anyway, otherwise you'd see > an error, rather than just the initial variable's value of 0. I did check the case and it was wrong. I changed it to match and it made a difference. I still don't think its working correctly. If your curious I have attached the text file that it is reading. my_path = "C:\\Ruby\\Text\\" WARNING = 0 ERROR = 0 d = Dir.new(my_path) d.each do |fl| unless fl == '.' or fl == '..' then puts my_path + fl File.open(my_path + fl, "r").each do |line| if line =~ /ERROR/ then error += 1 elsif line =~ /WARNING/ then warning += 1 end end end end puts warning.to_s puts error.to_s Attachments: http://www.ruby-forum.com/attachment/3372/log_file_20090221_041817.rar -- Posted via http://www.ruby-forum.com/.