开发者

From full path to file, to only displaying filename

How can I convert a full path

C:\some folder\another folder\my-picture开发者_Python百科.jpg

To:

my-picture.jpg

??

Thank you in advance.


You can read from the final \ (also works for bare "file.ext");

var fn = "C:\\some folder\\another folder\\my-picture.jpg";
alert( fn.substr(fn.lastIndexOf("\\") + 1) );


var str = "C:\\some folder\\another folder\\my-picture.jpg";
var fileName = str.split("\\").pop();

if you need to handle different OS file paths

var str = "C:\\some folder\\another folder\\my-picture.jpg";
var fileName = str.split(/[\\\/]/).pop();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜