Search
 
SCRIPT & CODE EXAMPLE
 

RUBY

ruby file extension

something.rb
Comment

ruby get file extension

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')					# => ""
Comment

PREVIOUS NEXT
Code Example
Ruby :: how to rename a table in ruby 
Ruby :: ruby uuid 
Ruby :: rails skip authenticity token 
Ruby :: rails remove column from model 
Ruby :: embedded ruby tag 
Ruby :: rails uniqueness 
Ruby :: dotenv-rails comments 
Ruby :: array ruby taking 3 last value 
Ruby :: ruby array includes 
Ruby :: ruby get file folder 
Ruby :: ruby each with index 
Ruby :: unix timestamp to date time rails 
Ruby :: rails check_box_tag 
Ruby :: length validation rails 
Ruby :: how to destroy a migration in rails 
Ruby :: ruby string to symbol 
Ruby :: ruby pop array 
Ruby :: new line in ruby 
Ruby :: rails run rspec 
Ruby :: ruby get current pid 
Ruby :: ruby check if constant exists 
Ruby :: ruby hello world 
Ruby :: how works httparty ruby 
Ruby :: call the api from ruby 
Ruby :: ruby array loop 
Ruby :: rails has_many through source 2 
Ruby :: what is touch in rails 
Ruby :: multiple seeds in rails 6 
Ruby :: rails date field default today 
Ruby :: using module function in main ruby 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =