-
-
Save enspdf/ccbf6b4ba87a002ffa063e1ba4885779 to your computer and use it in GitHub Desktop.
Revisions
-
lovasoa revised this gist
May 11, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,7 @@ const path = require("path"); async function* walk(dir) { for await (const d of await fs.promises.opendir(dir)) { const entry = path.join(dir, d.name); if (d.isDirectory()) yield* walk(entry); else if (d.isFile()) yield entry; } } -
lovasoa revised this gist
May 11, 2020 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ // Callback-based version for old versions of Node var fs = require("fs"), path = require("path"); -
lovasoa revised this gist
May 11, 2020 . 1 changed file with 18 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ // ES6 version using asynchronous iterators, compatible with node v10.0+ const fs = require("fs"); const path = require("path"); async function* walk(dir) { for await (const d of await fs.promises.opendir(dir)) { const entry = path.join(dir, d.name); if (d.isDirectory()) yield* await walk(entry); else if (d.isFile()) yield entry; } } // Then, use it with a simple async for loop async function main() { for await (const p of walk('/tmp/')) console.log(p) } -
lovasoa created this gist
Jan 29, 2014 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ var fs = require("fs"), path = require("path"); function walk(dir, callback) { fs.readdir(dir, function(err, files) { if (err) throw err; files.forEach(function(file) { var filepath = path.join(dir, file); fs.stat(filepath, function(err,stats) { if (stats.isDirectory()) { walk(filepath, callback); } else if (stats.isFile()) { callback(filepath, stats); } }); }); }); } if (exports) { exports.walk = walk; } else { walk(".", manageFile); }