You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
781 B
28 lines
781 B
import fs from "fs";
|
|
import path from "path";
|
|
|
|
const root = path.join(process.cwd(), "docx", "邮件");
|
|
|
|
type Entry = { rel: string; kind: "DIR" | "FILE"; size?: number };
|
|
|
|
function walk(dir: string, out: Entry[]) {
|
|
for (const e of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
const full = path.join(dir, e.name);
|
|
const rel = path.relative(root, full).split(path.sep).join("/");
|
|
if (e.isDirectory()) {
|
|
out.push({ rel, kind: "DIR" });
|
|
walk(full, out);
|
|
} else {
|
|
out.push({ rel, kind: "FILE", size: fs.statSync(full).size });
|
|
}
|
|
}
|
|
}
|
|
|
|
const out: Entry[] = [];
|
|
if (!fs.existsSync(root)) {
|
|
console.error("MISSING", root);
|
|
process.exit(1);
|
|
}
|
|
walk(root, out);
|
|
console.log(JSON.stringify({ root, count: out.length, entries: out }, null, 2));
|