-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfile-structs.js
More file actions
30 lines (22 loc) · 767 Bytes
/
file-structs.js
File metadata and controls
30 lines (22 loc) · 767 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
28
29
30
import fs from 'fs';
import path from 'path';
import util from 'util';
function printTree(dir, prefix = '', output = []) {
const files = fs.readdirSync(dir);
files.forEach((file, index) => {
const filePath = path.join(dir, file);
const stats = fs.statSync(filePath);
const isLast = index === files.length - 1;
if (file === '.git' || file === 'node_modules') {
return;
}
output.push(`${prefix}${isLast ? '└── ' : '├── '}${file}`);
if (stats.isDirectory()) {
printTree(filePath, `${prefix}${isLast ? ' ' : '│ '}`, output);
}
});
return output;
}
const output = printTree('./').join('\n');
fs.writeFileSync('file-structure.txt', output, 'utf-8');
console.log('File structure has been written to file-structure.txt');