| 64 | * under the directory. |
| 65 | */ |
| 66 | export function findImagesFromDirectoriesRecursive(dirPath) { |
| 67 | const imageFilePaths = []; |
| 68 | const items = fs.readdirSync(dirPath); |
| 69 | for (const item of items) { |
| 70 | const fullPath = path.join(dirPath, item); |
| 71 | if (fs.lstatSync(fullPath).isDirectory()) { |
| 72 | // NOTE: This doesn't follow symlinks. |
| 73 | try { |
| 74 | imageFilePaths.push(...findImagesFromDirectoriesRecursive(fullPath)); |
| 75 | } catch (err) {} |
| 76 | } else { |
| 77 | let extMatch = false; |
| 78 | for (const extName of IMAGE_EXTENSION_NAMES) { |
| 79 | if (item.toLowerCase().endsWith(extName)) { |
| 80 | extMatch = true; |
| 81 | break; |
| 82 | } |
| 83 | } |
| 84 | if (extMatch) { |
| 85 | imageFilePaths.push(fullPath); |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | return imageFilePaths; |
| 90 | } |