Tim Greer
3/1/2009 10:26:00 PM
Brad Winborg wrote:
> Tim Hunter wrote:
>> Brad Winborg wrote:
>>> error = 0
>>> end
>>> Not a directory - D:\My
>>> Documents\Replicon\log_file_20090221_041817.txt\ D:/My
>>> Documents/Replicon/ErrorCount.rb:6:in `initialize' Press ENTER to
>>> close the window...
>>>
>>> Directory Path
>>> D:\My Documents\Replicon
>>> I was going to add an attachment to show that the directory really
>>> exits and that the file is in that directory, but it was to large.
>>>
>>> If anyone has any ideas as to why it is not working I be very
>>> grateful, as I am new to ruby code in general.
>>
>> Look at the error message. You're asking Dir.new to open the
>> directory "D:\My Documents\Replicon\log_file_20090221_041817.txt".
>> I think the directory name is actually "D:\My Documents\Replicon" and
>> "log_file_20090221_041817.txt" is a file within that directory.
>
> Thank you that did help, but I still have a problem.
>
> 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
>
> The problem that I have now is that it apparently sees the file but
> does not read it.
>
> Below is the response that is returned.
>
> C:\Ruby\Text\log_file_20090221_041817.txt
> 0
> 0
> 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.
--
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting. 24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!