path = "/path/to/file.ext"
File.basename(path) # 'file.ext'
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"
# Alternative to File.extname(path) for multiple extension periods
def full_extname(path)
ext = File.basename(path).split('.', 2)[1]
ext.nil? ? '' : ".#{ext}"
end
full_extname('/path/to/xyz.mp4') # => ".mp4"
full_extname('/path/to/xyz.my.custom.ext.mp4') # => ".my.custom.ext.mp4"
full_extname('/path/to/xyz') # => ""