Skip to content

Commit d4cd590

Browse files
committed
flesh out lofic for when path is a dir
1 parent c4d2796 commit d4cd590

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

  • implement-shell-tools/wc

implement-shell-tools/wc/wc.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,5 +130,25 @@ def counter(item):
130130
print(f"{stats['characters']} {path}")
131131
else:
132132
print(f"{stats['lines']} {stats['words']} {stats['characters']} {path}")
133+
elif os.path.isdir(path):
134+
directory = "folder"
135+
136+
for file in os.listdir(directory):
137+
path = os.path.join(directory, file)
138+
139+
if os.path.isfile(path):
140+
with open(path, "r") as f:
141+
content = f.read()
142+
stats = counter(content)
143+
if args.line:
144+
print(f"{stats['lines']} {path}")
145+
elif args.word:
146+
print(f"{stats['words']} {path}")
147+
elif args.char:
148+
print(f"{stats['characters']} {path}")
149+
else:
150+
print(f"{stats['lines']} {stats['words']} {stats['characters']} {path}")
151+
152+
133153

134154

0 commit comments

Comments
 (0)