常用方法有兩種
以/Users/lz/project/test.txt爲例分別介紹一下
方法一、
fullPath = '/Users/lz/project/test.txt';
pos = fullPath.lastIndexOf('/');
fileName = fullPath.substr(pos+1);
console.log(fileName);
filePath = fullPath.substr(0,pos);
console.log(filePath);
方法二、
如果你已經知道文件名,那就更好辦了。
fullPath = '/Users/lz/project/test.txt';
fileName = 'test.txt';
filePath = fullPath.replace(fileName, '');
console.log(filePath);