Created
October 17, 2016 18:37
-
-
Save carlosascari/54badf03c8e89efa6956b47968f0f823 to your computer and use it in GitHub Desktop.
Unlink/Delete files and folders recursively
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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