MCPcopy Create free account
hub / github.com/DingyangLyu/MatClaw / findFileRecursive

Function findFileRecursive

src/web/server.ts:21–45  ·  view source on GitHub ↗

Recursively search for a file by basename within a directory (max 3 levels deep).

(
  dir: string,
  basename: string,
  root: string,
  depth = 0,
)

Source from the content-addressed store, hash-verified

19
20/** Recursively search for a file by basename within a directory (max 3 levels deep). */
21function findFileRecursive(
22 dir: string,
23 basename: string,
24 root: string,
25 depth = 0,
26): string | null {
27 if (depth > 3) return null;
28 try {
29 for (const entry of fs.readdirSync(dir)) {
30 const full = path.join(dir, entry);
31 if (entry === basename && fs.statSync(full).isFile()) return full;
32 if (
33 depth < 3 &&
34 fs.statSync(full).isDirectory() &&
35 !entry.startsWith('.')
36 ) {
37 const found = findFileRecursive(full, basename, root, depth + 1);
38 if (found) return found;
39 }
40 }
41 } catch {
42 /* permission or read error, skip */
43 }
44 return null;
45} // v4: compact md, no breaks, hide br
46
47let wss: WebSocketServer;
48

Callers 1

startDashboardFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected