Hash with files

Hello all,

I am trying to run File.size? on each file in my hash, yet I am getting
this error.
Goal ==> get file sizes stored in hash from Dir.glob

$ ruby test.rb
yes
test.rb:49:in size?': can't convert Array into String (TypeError) from test.rb:49 from test.rb:48:ineach_value’
from test.rb:48

apparently my hash value has to be converted to a string b4 testing it
with File.size?

Wonder if I have to use dirhsh.inspect to convert it to a string first?

$ ruby test.rb
yes
{“vrdevgzlogs”=>[“derek.log.gz”], “vrdevlogs”=>[“derek.log”]}
{“vrdevgzlogs”=>[“derek.log.gz”], “vrdevlogs”=>[“derek.log”]}

thank you!

On Fri, Apr 3, 2009 at 3:38 AM, Derek S.
[email protected] wrote:

   from test.rb:48:in `each_value'
   from test.rb:48

Dir.glob returns an array of matches. Could you post the code where
you’re constructing the hash?

martin

Martin DeMello wrote:

On Fri, Apr 3, 2009 at 3:38 AM, Derek S.
[email protected] wrote:

� � � �from test.rb:48:in `each_value’
� � � �from test.rb:48

Dir.glob returns an array of matches. Could you post the code where
you’re constructing the hash?

martin

Hi Martin,

here it is. its also in the attachment.

Dir.chdir(“/cygdrive/c/temp/log”) or raise StandardError, “Change dir
failed to ~aevvrlog!”

###-- Create hash with files for rolling from dir above --###
dirhsh = Hash.new 0
dirhsh[“vrdevlogs”] = Dir.glob(“.{log,out}“)
dirhsh[“vrdevgzlogs”] = Dir.glob(”
.{log,out}.gz”)

if ( dirhsh.length > 0 )
puts “yes”
dirhsh.each_value { |value|
puts dirhsh.inspect
if (File.size?(value) > FSIZE)
puts “Yes its larger”
end
else
raise StandardError, “Hash ‘dirhsh’ has no values, logs will not be
rolled!”
end

On Fri, Apr 3, 2009 at 4:17 AM, Derek S.
[email protected] wrote:

###-- Create hash with files for rolling from dir above --###
dirhsh = Hash.new 0
dirhsh[“vrdevlogs”] = Dir.glob(“.{log,out}“)
dirhsh[“vrdevgzlogs”] = Dir.glob(”
.{log,out}.gz”)

Note that Dir.glob returns an array, since there could be several
matching files

if ( dirhsh.length > 0 )
puts “yes”
dirhsh.each_value { |value|

So here value is an array of several files

   puts dirhsh.inspect

So now we want

value.each {|filename|
if File.size(filename) > FSIZE

martin