Created
April 23, 2025 07:26
-
-
Save TobidieTopfpflanze/fd9a3f00610f2f645606797fa14cdfeb to your computer and use it in GitHub Desktop.
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 characters
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