Delete several files in node.js

后端 未结 8 1411
自闭症患者
自闭症患者 2021-02-15 23:58

What is the best way to delete several files in node.js?

function deleteFiles(files, callback){
    ...
}

var files = [\'file1.js\', \'file2.jpg\', \'file3.css\         


        
8条回答
  •  难免孤独
    2021-02-16 00:06

    Best way is delete files synchronously into a loop using unlinkSync(path) function (see the doc), from node v7.6.0 so far.

    Syntax is provided below:

    // myListOfFiles will be your list of files with paths relative to your script.
    myListOfFiles.forEach(filePath => {
     fs.unlinkSync(filePath);
     return;
    });
    

    A reference here

提交回复
热议问题