import fs from 'fs'; import path from 'path'; export function forEachFiles( TPath: string, cb: (file: fs.Dirent) => void, options?: { recursive?: boolean; filter?: (file: fs.Dirent) => boolean; }, ) { const { recursive = true, filter = () => true } = options || {}; const targetFiles = fs .readdirSync(TPath, { withFileTypes: true }) .filter(filter); targetFiles.forEach((file) => { const filePath = path.resolve(TPath, file.name); if (recursive && file.isDirectory()) { forEachFiles(filePath, cb, { recursive, filter }); } cb(file); }); }