NodeJS_2505:node判断一个文件夹存在并创建目录和写入数据

 

node判断一个文件存在并创建目录和写入数据

  UserData.task_id = '980b2323-7412-4961-b967-e7d8e090febe';
  const filePath = path.join(__dirname, 'amain/' + driveID + '/uptext', UserData.task_id + '.txt');
  const dirPath = path.dirname(filePath);
  if (!fs.existsSync(dirPath)) {
    fs.mkdirSync(dirPath, { recursive: true });
    fs.writeFile(filePath, data, (err) => { err ? console.error('写入文字错误') : console.log('文字写入成功') });
  };

 

posted @ 2025-05-27 18:12  琥珀君  阅读(14)  评论(0)    收藏  举报