Skip to content

Commit ba64d28

Browse files
implement ls-1 command
1 parent d1ed6ca commit ba64d28

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

  • implement-shell-tools/ls

implement-shell-tools/ls/ls.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import os
2+
import argparse
3+
4+
# Setup argument parser
5+
parser = argparse.ArgumentParser(
6+
prog="ls",
7+
description="Lists contents of a directory"
8+
)
9+
10+
parser.add_argument("-1", dest="one_column", action="store_true", help="List one file per line")
11+
parser.add_argument("path", nargs='?', default=".", help="Directory to list (default: current directory)")
12+
13+
args = parser.parse_args()
14+
15+
# List directory contents
16+
files = os.listdir(args.path)
17+
18+
# Print each file
19+
for file in files:
20+
print(file)

0 commit comments

Comments
 (0)