Here our task is to print only the files and its size. In ruby, the code is as follows.
require 'FileUtils'
class DirectoryProbe
def self.print_all_files filename
if File.directory?(filename)
Dir.chdir(filename)
files = Dir['**/*']
files.each{ |file|
unless File.directory?(file)
puts "#{file} \t #{File.size(file)} bytes"
end
}
end
end
end
Dir.chdir(file) issues a command cd in windows and linux. The code Dir['**/*'] returns the array containing all the files in the directory recursively. After that I work on each file separately.
No comments:
Post a Comment