Skip to content

Commit 2bcbf2f

Browse files
committed
ls: -a flag
1 parent 21c46a6 commit 2bcbf2f

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

  • implement-shell-tools/ls

implement-shell-tools/ls/ls.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import argparse
2+
from os import listdir
23

34
parser = argparse.ArgumentParser(prog="ls", description="List directory contents. Ignore files and directories starting with a '.' by default")
45
parser.add_argument("-1", help="List one file per line.", action="store_true")
@@ -7,3 +8,16 @@
78

89
args = parser.parse_args()
910

11+
path = args.path
12+
13+
show_hidden = args.a
14+
15+
contents = []
16+
17+
for f in listdir(path):
18+
if show_hidden == False and f[0] != ".":
19+
contents.append(f)
20+
if show_hidden == True:
21+
contents.append(f)
22+
23+
print(contents)

0 commit comments

Comments
 (0)