Search
 
SCRIPT & CODE EXAMPLE
 

RUBY

ruby get file folder

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

get directory of current file ruby

__dir__
Comment

PREVIOUS NEXT
Code Example
Ruby :: ruby non greedy regex 
Ruby :: devise redirectt after sign up 
Ruby :: rails video_tag with <source 
Ruby :: shopify cart show total save 
Ruby :: ruby loop from the last array item 
Ruby :: ruby multiline comment 
Ruby :: List and delete migration from rails console 
Ruby :: ruby filter 
Ruby :: how to format date and time in rails 
Ruby :: rails load environment variables 
Ruby :: ruby substring remove 
Ruby :: liquid add date 
Ruby :: print in ruby 
Ruby :: add edit or --wait for rails credentials edit windows 
Ruby :: date class to unix timestamp ruby 
Ruby :: ruby each do method 
Ruby :: How To Set Up Ruby on Rails with Postgres 
Ruby :: ruby activerecord find where less than 
Ruby :: ruby push array 
Ruby :: validations rails integer suprior to 0 
Ruby :: rbenv not changing version 
Ruby :: generate view rails 
Ruby :: rails destroy something from db 
Ruby :: ruby on rails 4.2 how to add GET route 
Ruby :: Rails, using whenever gem in development 
Ruby :: next if ruby 
Ruby :: $stdout ruby override 
Ruby :: rails update column without callbacks 
Ruby :: rails decode cookie 
R :: r define nested empty list 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =