cialis online pharmacy generic xenical cheap cialis online cialis generic viagra online in canada buy cheap levitra online cialis without a perscription order viagra uk no prescription flagyl cheap generic levitra buying viagra in the uk cheap viagra approved cialis deltasone online buy viagra online without prescription non prescription cialis buy orlistat uk buy cialis in india prednisone 60 mg female viagra online buy viagra without prescription celebrex prescriptions buy cialis canada best prices viagra alternative to prednisone cheapest generic levitra levitra 5mg cheap viagra cialis on line buy xenical without prescription online accutane canadian health care prednisone no prescreption viagra online generic female viagra europe buy cialis low price cheap india viagra

Getting A File’s Information In Ruby Using File::Stat

Here’s another nice tip from Michael Morin on how to get a file’s information in Ruby using the File::Stat class; information such as such as file size, date last modified, date last accessed, and more. This can be quite useful in situations wherein you want to query the operating system about a particular file without having to open it.

An example scenario would be like this: a program has to iterate over the files in a directory and determine the files sizes and the total size. Plus, it must work recursively, totaling the file sizes of all the files in all subdirectories of the current directory. To be able to achieve this task, we use the find library included with Ruby.

#!/usr/bin/env ruby
require "find"

files = []
total = 0
Find.find('.') do|f|
 files << f
 total += File.stat(f).size

puts "There are #{files.length} files"
puts "They are %0.2f megabytes in size" % (total / 1024.0 / 1024.0)

Related Posts

Adding Instagram Badges to Your WordPress Profile

How to Create a Custom WordPress Registration Form with Flat UI

How to Create A Basic Hipster-Style Layout

How to Style Nav Links Using Floats With HTML5 and CSS3