Ruby - Using class methods from File class

Description

Using class methods from File class

Demo

fn = 'main.rb' 
if File.exist?(fn) then 
   puts(File.expand_path(fn)) # from  w  ww  .  j a v a  2 s.  c o m
   puts(File.basename(fn)) 
   puts(File.dirname(fn)) 
   puts(File.extname(fn)) 
   puts(File.mtime(fn)) 
   puts("#{File.size(fn)} bytes") 
else 
   puts( "Can't find file!") 
end

Result

Related Topic