# /rails_app_generator/cli/profile.rb
# Name of current program file
puts __FILE__ # => /rails_app_generator/cli/profile.rb
puts File.dirname(__FILE__) # => /rails_app_generator/cli
puts File.basename(__FILE__) # => profile.rb
# Name of starting program file
puts $0 # => exe/rag
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') # => ""