Skip to content

Instantly share code, notes, and snippets.

@niugm
Created October 19, 2022 08:29
Show Gist options
  • Save niugm/329af6eade6b2446ea7be540a85d0285 to your computer and use it in GitHub Desktop.
Save niugm/329af6eade6b2446ea7be540a85d0285 to your computer and use it in GitHub Desktop.
[utils] JavaScript utils functions #javascript #node.js
const fs = require('fs-extra');
const path = require('path');
function readdirSyncRecursive(dir, fileList = []) {
const files = fs.readdirSync(dir);
files.forEach((file) => {
const filePath = path.join(dir, file);
if (fs.statSync(filePath).isDirectory()) {
readdirSyncRecursive(filePath, fileList);
} else {
fileList.push(filePath);
}
});
return fileList;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment