Needing a little help with a ruby program

S

spudicus87

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
 
T

Trans

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 =3D Dir.new("#{ARGV[0]}")

disk_usage_info =3D `du #{specified_directory} -a`

file_size =3D Hash.new(0)

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

end

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

=A0 =A0 =A0 =A0 size =3D '#' * size / 1024

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

=A0 =A0 =A0 =A0 else
=A0 =A0 =A0 =A0 =A0 puts file

=A0 =A0 =A0 end

=A0 =A0 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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top