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();
精彩评论