Forum: Ruby Needing a little help with a ruby program

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
2747d6ada0b339140a590500306992b4?d=identicon&s=25 unknown (Guest)
on 2008-10-11 20:55
(Received via mailing list)
Ok, so this is what I need to do for the program. I am not the best
programmer in the world and I need a little help.

Assignment:

Create a program that obtains disk usage information from du and uses
it to print a histogram of the disk usage of the directories given as
command line arguments. The histogram should consist of a string with
one hash mark per megabyte of disk usage.



This is what I have so far.


require 'fileutils'

specified_directory = Dir.new("#{ARGV[0]}")

disk_usage_info = `du #{specified_directory} -a`

file_size = Hash.new(0)


disk_usage_file.each_line do |file, size|
  #Builds the hash with the filename and the sizes

end

file_size.each do|file, size|
        #changes value to histogram of numbers and shows results

        size = '#' * size / 1024

        if times < 0
          puts file +"\t | " + size

        else
          puts file

      end

    end


I think I have the first part and the last part down pretty well, I am
stuck on how to get the du output into the hash so I can output it
correctly. Any help would be appreciated.

Thanks,

Spudicus87
45196398e9685000d195ec626d477f0e?d=identicon&s=25 Thomas Sawyer (7rans)
on 2008-10-11 21:01
(Received via mailing list)
On Oct 11, 2:52 pm, spudicu...@gmail.com wrote:
> This is what I have so far.
>   #Builds the hash with the filename and the sizes
>
>         else
>           puts file
>
>       end
>
>     end
>
> I think I have the first part and the last part down pretty well, I am
> stuck on how to get the du output into the hash so I can output it
> correctly. Any help would be appreciated.

Study Regexp.

T.
This topic is locked and can not be replied to.