Created
January 13, 2017 15:45
-
-
Save yuqianma/3b28074255f1d8798ca998cf62980874 to your computer and use it in GitHub Desktop.
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') | |
function rmPath(path, cb) { | |
fs.lstat(path, (err, stats) => { | |
//console.log('retrieve:', path) | |
if (stats.isDirectory()) { | |
fs.readdir(path, (err, files) => { | |
let len = files.length + 1 | |
let checkDir = () => { | |
//console.log(path + ' left:', len-1) | |
if (!--len) { | |
//console.log('remove dir:', path) | |
fs.rmdir(path, cb) | |
} | |
} | |
checkDir() | |
files.map(f => rmPath(path + '/' + f, checkDir)) | |
}) | |
return | |
} | |
//console.log('remove file:', path) | |
fs.unlink(path, cb) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment