Node.js判断文件夹不存在就新建的功能
const fileDir: any = './wwwasaicc/guoyansai/';
// 不存在文件夹,直接创建
const Folder = async (reaPath: any) => {
const absPath = path.resolve(__dirname, reaPath);
try {
await fs.promises.stat(absPath);
} catch (e) {
// {recursive: true} 这个配置项是配置自动创建多层文件夹
await fs.promises.mkdir(absPath, { recursive: true });
}
};
// 执行建立需要储存的数据文件夹
try {
Folder(fileDir);
} catch (err) {
console.log(666.101, err);
}