Write a Ruby program to accept a filename from the user print the extension of that.
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
File name: test.rb Base name: test Extention: .rb Path name: /user/system
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Ruby Code: