Skip to content

Commit 3c8e345

Browse files
committed
shows error message if trying to read a dictory
1 parent 2c3458f commit 3c8e345

1 file changed

Lines changed: 23 additions & 6 deletions

File tree

  • implement-shell-tools/wc

implement-shell-tools/wc/wc.js

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { program } from "commander";
2-
import fs from "node:fs";
2+
import fs, { chownSync } from "node:fs";
33
import process from "node:process";
44

55
program
@@ -13,10 +13,10 @@ program
1313
program.parse();
1414

1515
const options = program.opts();
16-
const files = program.args;
16+
const paths = program.args;
1717

1818
console.log(options);
19-
console.log(files);
19+
console.log(paths);
2020

2121
// if no -lwc flags are supplied, wc prints
2222
// lines, words, bytes of each file
@@ -27,7 +27,24 @@ if (Object.keys(options).length === 0) {
2727
}
2828

2929
/*
30-
array of objects with data [{l: 2, w: 12: c: 123, file: 'sample-files/1.txt}, ...]
31-
For each item, create a temp string
32-
If options.l, append to temp string the w value
30+
for each path:
31+
if path is not a directory, show error message
32+
else:
33+
create a temporary array
34+
if l in options:
35+
push line count to temp arr
36+
if w in options:
37+
push word count into temp arr
38+
if c in options:
39+
push byte count into data
40+
41+
join the array with path and print
3342
*/
43+
44+
for (const path of paths) {
45+
if (fs.statSync(path).isDirectory()) {
46+
console.log(`wc: ${path}: read: Is a directory`);
47+
} else {
48+
console.log(`${path} is a file`);
49+
}
50+
}

0 commit comments

Comments
 (0)