-
Notifications
You must be signed in to change notification settings - Fork 0
/
read_dir.ts
51 lines (44 loc) · 1.36 KB
/
read_dir.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { generateNameString } from "./generate_name_string.ts";
import { generatePathString } from "./generate_path_string.ts";
let treeString = ''
const dirProperties = {
files: 0,
symlinks: 0,
directories: 0
}
export function readDir(pathEntries : string[], indents : boolean[] = []) {
[...Deno.readDirSync(pathEntries.join(''))].forEach((dirEntry, dirIndex, dirs) => {
const isLast = (dirIndex == dirs.length - 1);
treeString = treeString + generatePathString(indents, {
straight: '│ ',
empty: ' '
}) + generateNameString(
dirEntry.name,
isLast,
{
isFile: dirEntry.isFile,
isDirectory: dirEntry.isDirectory,
isSymlink: dirEntry.isSymlink
},
{
end: '└─ ',
breakout: '├─ '
}
) + '\n';
if (dirEntry.isFile) {
dirProperties.files++
}
if (dirEntry.isSymlink) {
dirProperties.symlinks++
}
if (dirEntry.isDirectory) {
dirProperties.directories++
indents.push(!isLast);
pathEntries.push(`${dirEntry.name}/`);
readDir(pathEntries, indents);
}
})
indents.pop();
pathEntries.pop();
return {treeString, dirProperties};
}