generated from Cloudymap1e/al-folio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdir-names.ts
28 lines (22 loc) · 864 Bytes
/
dir-names.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import * as fs from "fs";
import * as path from "path";
interface DirectoryStructure {
name: string;
type: "file" | "directory";
children?: DirectoryStructure[];
}
function getDirectoryStructure(dirPath: string): DirectoryStructure {
const stats = fs.statSync(dirPath);
const info: DirectoryStructure = {
name: path.basename(dirPath),
type: stats.isDirectory() ? "directory" : "file",
};
if (stats.isDirectory()) {
info.children = fs.readdirSync(dirPath).map((child) => getDirectoryStructure(path.join(dirPath, child)));
}
return info;
}
const rootDir = __dirname; // Use the current directory of the script
const structure = getDirectoryStructure(rootDir);
fs.writeFileSync("directory-structure.json", JSON.stringify(structure, null, 2), "utf-8");
console.log("Directory structure has been saved to directory-structure.json");