开发者

From full path to file, to only displaying filename

开发者 https://www.devze.com 2023-03-27 16:36 出处:网络
How can I convert a full path C:\\some folder\\another folder\\my-picture开发者_Python百科.jpg To:

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

精彩评论

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