Ruby Filename From Path

[Solved] Ruby Filename From Path | Ruby - Code Explorer | yomemimo.com
Question : ruby filename from path

Answered by : julio-corradi

path = "/path/to/file.ext"
File.basename(path) # 'file.ext'

Source : https://stackoverflow.com/questions/20793180/get-file-name-and-extension-in-ruby | Last Update : Mon, 07 Sep 20

Question : ruby file name path

Answered by : mysterious-mantis-2t9yeiqzzhwz

path = "/path/to/xyz.mp4"
File.basename(path) # => "xyz.mp4"
File.extname(path) # => ".mp4"
File.basename(path, ".mp4") # => "xyz" OR
File.basename(path, ".*") # => "xyz"
File.dirname(path) # => "/path/to"

Source : https://stackoverflow.com/questions/20793180/get-file-name-and-extension-in-ruby | Last Update : Fri, 29 Jul 22

Answers related to ruby filename from path

Code Explorer Popular Question For Ruby