| 12 | // This function checks each entry in the directory: if it's a file matching the filename, it returns its path. |
| 13 | // If it's a directory, the function recurses into it. |
| 14 | function searchDirectory(currentPath) { |
| 15 | const entries = fs.readdirSync(currentPath, { withFileTypes: true }) |
| 16 | |
| 17 | for (let entry of entries) { |
| 18 | const entryPath = path.join(currentPath, entry.name) |
| 19 | |
| 20 | if (entry.isDirectory()) { |
| 21 | const result = searchDirectory(entryPath) |
| 22 | if (result) return result |
| 23 | } else if (entry.isFile() && entry.name === filename) { |
| 24 | return entryPath |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | // If no file is found, return null. |
| 29 | return null |
| 30 | } |
| 31 | |
| 32 | return searchDirectory(folder) |
| 33 | } |