10 lines
342 B
JavaScript
10 lines
342 B
JavaScript
|
function getBaseFileName(fullPath) {
|
||
|
return fullPath.replace(/.*[\/\\]/, '');
|
||
|
}
|
||
|
|
||
|
// 测试
|
||
|
const filePath = 'C:\\Users\\username\\Documents\\example.txt';
|
||
|
console.log(getBaseFileName(filePath)); // 输出: example.txt
|
||
|
|
||
|
const filePath2 = '/home/user/documents/example.txt';
|
||
|
console.log(getBaseFileName(filePath2)); // 输出: example.txt
|