title: Cut off the filename and extension of a given string
body: <p>I build a little script that parses a directory for files of a given filetype and stores the location (including the filename) in an array. This look like this:</p>
  
  <pre><code>def getFiles(directory)
    arr = Dir[directory + '/**/*.plt']
    arr.each do |k|
      puts "#{k}"
    end
  end
  </code></pre>
  
  <p>The output is the path and the files. But I want only the path.</p>
  
  <p>Instead of /foo/bar.txt I want only the /foo/</p>
  
  <p>My first thought was a regexp but I am not sure how to do that.</p>