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)) # www .j  ava 2s  .  c om
   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