There was an error while loading. Please reload this page.
1 parent c8e7c29 commit bc623a1Copy full SHA for bc623a1
1 file changed
implement-shell-tools/wc/wc.js
@@ -27,9 +27,22 @@ if (Object.keys(options).length === 0) {
27
// incrementally updated in the loop below
28
const totals = { l: 0, w: 0, c: 0 };
29
30
+// wc actually prints total if there is more than one argument, not more than one file
31
+// e.g. wc invalid.txt valid.txt
32
+// there will be a total line with the same stats are the valid.txt stats
33
let fileCount = 0;
34
+
35
for (const path of paths) {
- if (fs.statSync(path).isDirectory()) {
36
+ let isDir;
37
+ try {
38
+ isDir = fs.statSync(path).isDirectory();
39
+ } catch (err) {
40
+ console.error(`wc: ${path} open: No such file or directory`);
41
+ fileCount++;
42
+ continue;
43
+ }
44
45
+ if (isDir) {
46
console.eror(`wc: ${path}: read: Is a directory`);
47
} else {
48
fileCount++;
0 commit comments