Created
February 8, 2014 22:01
-
-
Save joliss/8890977 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
// `walkSync(baseDir)` is a faster substitute for | |
// glob.sync('**', { | |
// cwd: baseDir, | |
// dot: true, | |
// mark: true, | |
// strict: true | |
// }) | |
// | |
// `baseDir` must not be ''; pass '.' instead | |
exports.walkSync = walkSync | |
function walkSync (baseDir, relativePath) { | |
// Inside this function, prefer string concatenation to the slower path.join | |
// https://github.com/joyent/node/pull/6929 | |
if (relativePath == null) { | |
relativePath = '' | |
} else if (relativePath.slice(-1) !== '/') { | |
relativePath += '/' | |
} | |
var results = [] | |
var entries = fs.readdirSync(baseDir + '/' + relativePath) | |
for (var i = 0; i < entries.length; i++) { | |
var stats = fs.statSync(baseDir + '/' + relativePath + entries[i]) | |
if (stats.isDirectory()) { | |
results.push(relativePath + entries[i] + '/') | |
results = results.concat(walkSync(baseDir, relativePath + entries[i])) | |
} else { | |
results.push(relativePath + entries[i]) | |
} | |
} | |
return results | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment