删除文件
var fs = require(‘fs‘); fs.unlink(path,callback);
删除文件夹
deleteFolder(path); function deleteFolder(path) { var files = []; if( fs.existsSync(path) ) { files = fs.readdirSync(path); files.forEach(function(file,index){ var curPath = path + "/" + file; if(fs.statSync(curPath).isDirectory()) { // recurse deleteFolder(curPath); } else { // delete file fs.unlinkSync(curPath); } }); fs.rmdirSync(path); } }
时间: 2024-10-06 04:47:15