const fs = require('fs');
// directory path
const dir = 'temp';
// delete directory recursively
try {
fs.rmdirSync(dir, { recursive: true });
console.log(`${dir} is deleted!`);
} catch (err) {
console.error(`Error while deleting ${dir}.`);
}
const fs = require('fs');
fs.rmSync(folderPath, { recursive: true })
//DeprecationWarning: In future versions of Node.js, fs.rmdir(path, { recursive: true }) will be removed.
//Use fs.rm(path, { recursive: true }) instead
fs.rm(path, { recursive: true })
fs.unlink('./node/myText.txt',function(){
fs.rmdir('node');
});
const fs = require('fs');
const Path = require('path');
const deleteFolderRecursive = function (directoryPath) {
if (fs.existsSync(directoryPath)) {
fs.readdirSync(directoryPath).forEach((file, index) => {
const curPath = path.join(directoryPath, file);
if (fs.lstatSync(curPath).isDirectory()) {
// recurse
deleteFolderRecursive(curPath);
} else {
// delete file
fs.unlinkSync(curPath);
}
});
fs.rmdirSync(directoryPath);
}
};