Skip to content

Commit 4ee9b6f

Browse files
committed
Complete the implementation of Python ls.
1 parent b3faa6b commit 4ee9b6f

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

  • implement-shell-tools/ls

implement-shell-tools/ls/ls.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
help="list one file per line")
1111

1212
parser.add_argument("-a",
13+
dest="show_hidden_files",
1314
action="store_true",
1415
help="show hidden files")
1516

@@ -18,3 +19,15 @@
1819
default=".")
1920

2021
args = parser.parse_args()
22+
23+
entries = os.listdir(args.filepath)
24+
25+
if not args.show_hidden_files:
26+
entries = [entry for entry in entries if not entry.startswith(".")]
27+
28+
if args.one_per_line:
29+
for entry in entries:
30+
print(entry)
31+
else:
32+
joined = "\t".join(entries)
33+
print(joined)

0 commit comments

Comments
 (0)