title: Get file name and extension in Ruby
body: <p>I'm working on a program to download a video from YouTube, convert it to MP3 and create a directory structure for the files.</p>
  
  <p>My code is:</p>
  
  <pre><code>FileUtils.cd("#{$musicdir}/#{$folder}") do
    YoutubeDlhelperLibs::Downloader.get($url)
    if File.exists?('*.mp4')
      puts 'Remove unneeded tempfile'
      Dir['*.mp4'].each do |waste|
        File.delete(waste)
      end
    else
      puts 'Temporary file already deleted'
    end
  
    Dir['*.m4a'].each do |rip|
      rip.to_s
      rip.split
      puts 'Inside the function'
      puts rip
    end
  
  end
  </code></pre>
  
  <p>The first one goes to the already created music folder. Inside that I'm executing <code>get</code>. After that I have two files in the directory: "xyz.mp4" and "xyz.m4a".</p>
  
  <p>I would like to fetch the filename without the extension so I can handle both files differently.</p>
  
  <p>I'm using an array, but an array for just one match sounds crazy for me.</p>
  
  <p>Has anyone another idea?</p>