We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 56e2740 commit 1bcd513Copy full SHA for 1bcd513
1 file changed
implement-shell-tools/ls/ls.js
@@ -0,0 +1,23 @@
1
+import { program } from "commander";
2
+import { promises as fs } from "node:fs";
3
+
4
+//configuring
5
+program
6
+ .name("ls")
7
+ .description("list directory contents")
8
+ .option("-1, --one", "Outputs are printed one entry per line")
9
+ .argument("[directory]", "Directory to list", "."); // "." means current directory
10
11
+//interpret the program
12
+program.parse();
13
+const directory = program.args[0] || "."; //get dir arg- 1st arg in program.args array || if no arg default to current dir
14
15
16
+const files = await fs.readdir(directory); //read the dir to get array of filenames
17
18
19
20
+//print each file on its own line
21
+for (const file of files) { // Loop prints each individually on separate lines
22
+ console.log(file)
23
+}
0 commit comments