Avatar of rbwin
rbwin
 asked on

I have ruby program that reads an error log txt file

This is a question I  introduced on Saturday.I have anywhere from 1 to X number of error logs that are text files. It is to the point where it recognizes the error log. It is then suppose to read the file and find how many times the word WARNING is listed and how many times the word ERROR is listed. As I said it finds the file and does not give an error but it also reports WARNING = 0 and ERROR = 0.
I have pasted the code and the result when it is run below and I have attached the text file I have been using to test with.

# fill in the path of the input files here
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

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Brad>cd c:\ruby

C:\Ruby>ruby 1.rb
C:\Ruby\Text\log_file_20090227_030614.txt
0
0

C:\Ruby>
log-file-20090227-030614.txt
Ruby

Avatar of undefined
Last Comment
Gertone (Geert Bormans)

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Gertone (Geert Bormans)

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Your help has saved me hundreds of hours of internet surfing.
fblack61