-
-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathls.js
More file actions
27 lines (24 loc) · 662 Bytes
/
ls.js
File metadata and controls
27 lines (24 loc) · 662 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
import process from "node:process";
import { promises as fs } from "node:fs";
const argv = process.argv.slice(2, process.argv.length);
const currentDir = './';
const flags = [];
let path = '';
for (let i = 0; i < argv.length; i++) {
if (argv[i][0] == "-") {
flags.push(argv[i]);
} else {
path = argv[i];
}
}
if (path == '') path = currentDir;
const content = await fs.readdir(path);
if (flags.includes("-l")) {
for (let i = 0; i < content.length; i++) {
let line = content[i];
if (!flags.includes("-a") && line[0] == ".") continue;
console.log(line);
}
} else {
console.log(content.join(" "));
}