ez-common-ts/src/commons/file-util.ts

32 lines
920 B
TypeScript
Raw Normal View History

2023-11-12 22:00:29 +08:00
/**
*
* @param fileName
* @returns
*/
export function getFileExt(fileName: string): string {
const index = fileName.lastIndexOf(".");
if (index === -1) {
return "";
}
return fileName.substring(index + 1);
}
/**
*
*
*
* 使substring方法提取最后一个斜杠或反斜杠后面的字符串作为文件名并返回
* @param path
* @returns
*/
export function getFileName(path: string): string {
let index = path.lastIndexOf("/");
if (index === -1) {
index = path.lastIndexOf("\\");
if (index === -1) {
return path;
}
}
return path.substring(index + 1);
}