title: I'd like to remove the filename from a path using JavaScript
body: <p>Using Javascript I'd like to remove the filename from the end of a string (path+filename), leaving me just the directory path.</p>
  
  <p>Would regular expressions be ideal? Or, is there a simpler means of doing this using the string object?</p>
  
  <p>Thanks for any help!</p>
  
  <p>----ANSWERED &amp; EXPLAINED---</p>
  
  <p>The purpose of this code was to open finder to a directory. The data I was able to extract included a filename - since I was only trying to open finder (mac) to the location, I needed to strip the filename. Here's what I ended up with:</p>
  
  <pre><code>var theLayer = app.project.activeItem.selectedLayers[0];
  //get the full path to the selected file
  var theSpot = theLayer.source.file.fsName;
  //strip filename from the path
  var r = /[^\/]*$/;
  var dirOnly = theSpot.replace(r, '');
  //use 'system' to open via shell in finder
  popen = "open"
  var runit = system.callSystem(popen+" "+"\""+dirOnly+"\"");
  </code></pre>