Q:

Write a Ruby program to accept a filename from the user print the extension of that

0

Write a Ruby program to accept a filename from the user print the extension of that.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Ruby Code:

file = "/user/system/test.rb"
# file name
fbname = File.basename file  
puts "File name: "+fbname 
# basename
bname = File.basename file,".rb"
puts "Base name: "+bname 
# file extention
ffextn = File.extname  file   
puts "Extention: "+ffextn 
# path name
path_name= File.dirname  file 
puts "Path name: "+path_name
Output:
File name: test.rb
Base name: test
Extention: .rb
Path name: /user/system

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now