Skip to content

Instantly share code, notes, and snippets.

@TobidieTopfpflanze
Created April 23, 2025 07:26
Show Gist options
  • Save TobidieTopfpflanze/fd9a3f00610f2f645606797fa14cdfeb to your computer and use it in GitHub Desktop.
Save TobidieTopfpflanze/fd9a3f00610f2f645606797fa14cdfeb to your computer and use it in GitHub Desktop.
function getFilePaths(
folderPath,
customFilter = () => true,
maxDepth = -1,
depth = 0
) {
if (depth == maxDepth) return [];
const entries = readdirSync(folderPath).map((entries) =>
Path.join(folderPath, entries)
);
const files = []
for (const entry of entries) {
if(statSync(entry).isFile() && customFilter(entry)) {
files.push(entry)
}
if(statSync(entry).isDirectory()) {
files.push(...getFilePaths(entry, customFilter, maxDepth, depth + 1))
}
}
return files;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment