Ruby Basic Exercises: Print the extension name of the file
Ruby Basic: Exercise-7 with Solution
Write a Ruby program to accept a filename from the user print the extension of that.
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
Ruby Code Editor:
Contribute your code and comments through Disqus.p>Previous: Write a Ruby program which accept the user's first and last name and print them in reverse order with a space between them.
Next: Write a Ruby program to check two integer values whether either of them is in the range 20..30 inclusive.
What is the difficulty level of this exercise?
- New Content published on w3resource:
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework