目标
用显式栈迭代遍历目录,收集全部文件路径后统计总数、总字节与逐扩展名的文件数与字节数。
要点
符号链接默认跳过避免成环与越出根目录(Windows 无符号链接权限的测试自动 skip);无扩展名文件归入 (none) 桶;demo 输出 files=3 bytes=26 与逐扩展名表。
提示
遍历是同步单线程的——超大树会阻塞事件循环,冷缓存时 stat 调用占主导。
验证
node –test 在生成的临时树上验证收集、分组、符号链接与无扩展名四个行为;CLI 对示例目录输出统计表。 复现命令:
node --test walkstats.test.mjs
node walkstats.mjs ./src
预期输出要点:For a temp tree of text and json files the CLI prints totals plus a per-extension table sorted by bytes.
实测证据:Node 22.23.2: node –test -> 3 passed, 1 skipped (Windows symlink permission); CLI printed files=3 bytes=26 with a per-extension breakdown.