Skip to content

Instantly share code, notes, and snippets.

@carlosascari
Created October 17, 2016 18:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlosascari/54badf03c8e89efa6956b47968f0f823 to your computer and use it in GitHub Desktop.
Save carlosascari/54badf03c8e89efa6956b47968f0f823 to your computer and use it in GitHub Desktop.
Unlink/Delete files and folders recursively
const fs = require('fs');
const unlinkRecursive = path => {
if (fs.existsSync(path)) {
fs.readdirSync(path).forEach((file, index) => {
fs.lstatSync(`${path}/${file}`).isDirectory()
? unlinkRecursive(`${path}/${file}`)
: fs.unlinkSync(`${path}/${file}`);
});
fs.rmdirSync(path);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment