Skip to content

Instantly share code, notes, and snippets.

@lunaroyster
Forked from VinGarcia/walksync.js
Last active January 27, 2018 15:13
Show Gist options
  • Save lunaroyster/8cfc7a93e038f23e0a524458adc74cd0 to your computer and use it in GitHub Desktop.
Save lunaroyster/8cfc7a93e038f23e0a524458adc74cd0 to your computer and use it in GitHub Desktop.
// List all files in a directory in Node.js recursively in an asynchronous fashion
let walkAsync = async(dir, filelist)=> {
if( dir[dir.length-1] != '/') dir=dir.concat('/')
let fse = fse || require('fs-extra'),
files = await fse.readdir(dir);
filelist = filelist || [];
for (let file of files) {
if ((await fse.stat(dir + file)).isDirectory()) {
filelist = await walkSync(dir + file + '/', filelist);
}
else {
filelist.push(dir+file);
}
}
return filelist;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment