import { fs } from 'fs'
async isfileExist(path: string): Promise<boolean> {
return new Promise<any>((resolve) =>
fs.access(themePath, fs.constants.F_OK, (err: any) => resolve(!err))
);
}
如代码所示,通过返回值判断,如果返回true则存在,反之不存在。
const path = "./users/demo";
const result = await this.isThemeExists(path);
if (result) {
console.log(`${path}存在`);
}