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 :: ruby file write 
Ruby :: rails g model references 
Ruby :: ruby check if exists 
Ruby :: ruby/rails file get line number 
Ruby :: ruby capitalize first character of sentence 
Ruby :: ruby array has element 
Ruby :: ruby list all class methods 
Ruby :: ruby each char with index 
Ruby :: rails find_by order 
Ruby :: rails validate email 
Ruby :: sort hash ruby 
Ruby :: ruby square root 
Ruby :: if rails.env.development 
Ruby :: symbol to string ruby 
Ruby :: times ruby 
Ruby :: rails logger stdout 
Ruby :: ruby string trmi 
Ruby :: ruby array 
Ruby :: ruby while loop 
Ruby :: selenium webdriver get attribute ruby 
Ruby :: how to upload a file in capybara spec 
Ruby :: ruby constructors 
Ruby :: rails migration populate data 
Ruby :: rails start id to 1000 
Ruby :: Error occurred while parsing request parameters. 
Ruby :: rails check test database 
Ruby :: csv parse ruby 
Ruby :: how to comment out embedded ruby 
Ruby :: compiler version at runtime 
R :: linetype ggplot in r 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =