-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshowfile.js
More file actions
27 lines (20 loc) · 820 Bytes
/
showfile.js
File metadata and controls
27 lines (20 loc) · 820 Bytes
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
const fs = require("fs");
const path = require("path");
const excludedDirs = ["node_modules",'.git']; // 要排除的文件夹列表
const generateDirectoryStructure = (dir, prefix = "") => {
const files = fs.readdirSync(dir);
files.forEach((file, index) => {
const isExcluded = excludedDirs.includes(file);
if (isExcluded) return;
const fullPath = path.join(dir, file);
const isLast = index === files.length - 1;
const newPrefix = prefix + (isLast ? "└── " : "├── ");
console.log(prefix + newPrefix + file);
if (fs.lstatSync(fullPath).isDirectory()) {
generateDirectoryStructure(fullPath, prefix + (isLast ? " " : "| "));
}
});
};
const rootDir = path.join(__dirname, ""); // 你的根目录
console.log(rootDir);
generateDirectoryStructure(rootDir);