Delete several files in node.js

后端 未结 8 1414
自闭症患者
自闭症患者 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:23

    This is what I am currently using and works a treat:

    var files = ['file1.js', 'file2.jpg', 'file3.css'];
        
        function deleteFiles(files){
            for (const file of files) {
                fs.unlink((file), err => {
                    if (err) throw err;
                });
            };
        }
    
    deleteFiles(files);
    

提交回复
热议问题