Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

//递归删除目录的同步方法
export function rmdirFolderSync(url) {
var files = [];

if (fs.existsSync(url)) {
  files = fs.readdirSync(url);
  files.forEach(function (file, index) {
    var curPath = path.join(url, file);
    if (fs.statSync(curPath).isDirectory()) {
      rmdirFolderSync(curPath,);
    } else {
      fs.unlinkSync(curPath);
      console.log("删除成功>>>");
    }
  });
  fs.rmdirSync(url);
} else {
  console.log("给定的路径不存在,请给出正确的路径>>>");
}

}


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
3.5k views
Welcome To Ask or Share your Answers For Others

1 Answer

try catch


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...