Skip to content

Commit

Permalink
Update walkSync.js
Browse files Browse the repository at this point in the history
  • Loading branch information
3vorp committed Apr 11, 2024
1 parent 14c8090 commit 2b73bed
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions helpers/walkSync.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { readdirSync, statSync } = require("fs");
const { sep } = require("path");

/**
* Return an array of all filepaths in a directory
Expand All @@ -9,11 +10,11 @@ const { readdirSync, statSync } = require("fs");
*/
module.exports = function walkSync(dir, filelist = []) {
// add trailing slash if not present
if (dir[dir.length - 1] != "/") dir += "/";
if (dir[dir.length - 1] != sep) dir += sep;
for (const file of readdirSync(dir)) {
if (statSync(dir + file).isDirectory())
// read directories inside directories recursively
filelist = walkSync(dir + file + "/", filelist);
filelist = walkSync(dir + file + sep, filelist);
else filelist.push(dir + file);
}
return filelist;
Expand Down

0 comments on commit 2b73bed

Please sign in to comment.