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 4350f48 commit fa3da24Copy full SHA for fa3da24
1 file changed
implement-shell-tools/ls/ls.js
@@ -0,0 +1,25 @@
1
+const fs = require("fs");
2
+
3
+const args = process.argv.slice(2);
4
5
+const showAll = args.includes("-a");
6
7
+const dirArg = args.find(arg => !arg.startsWith("-"));
8
+const directory = dirArg || ".";
9
10
+fs.readdir(directory, (err, files) => {
11
+ if (err) {
12
+ console.error(err.message);
13
+ return;
14
+ }
15
16
+ let output = files;
17
18
+ if (!showAll) {
19
+ output = files.filter(file => !file.startsWith("."));
20
+ } else {
21
+ output = [".", "..", ...files];
22
23
24
+ output.forEach(file => console.log(file));
25
+});
0 commit comments