使用Javascript我想从字符串末尾(路径+文件名)中删除文件名,只留下目录路径.
正则表达式是理想的吗?或者,是否有更简单的方法使用字符串对象?
谢谢你的帮助!
----解答和解释---
此代码的目的是将finder打开到目录.我能够提取的数据包括一个文件名 - 因为我只是试图打开finder(mac)到该位置,我需要删除文件名.这是我最终得到的:
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+"\"");
Run Code Online (Sandbox Code Playgroud) 我需要使用regExp提取文件的完整路径
mydomain.com/path/to/file/myfile.html -> mydomain.com/path/to/file/
/mypath/file.txt -> /mypath/
任何人?
我有一个网址http://xyz.in/pqr/v/index.php,我想只获得http://xyz.in/pqr/v/所以如何从url中删除index.php.