Skip to content

Commit e8ac9af

Browse files
committed
ls
1 parent 19bbd49 commit e8ac9af

File tree

1 file changed

+23
-0
lines changed
  • implement-shell-tools/ls

1 file changed

+23
-0
lines changed

implement-shell-tools/ls/ls.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import argparse
2+
import os
3+
4+
parser = argparse.ArgumentParser(description="Display one file per line from ls directory")
5+
6+
parser.add_argument("-1", dest="one", action="store_true", help="List one file per line")
7+
parser.add_argument("-a", action="store_true", help="Include hidden files (those starting with .)")
8+
parser.add_argument("path", nargs="?", default=".", help="The directory to list (default: current directory)")
9+
10+
args = parser.parse_args()
11+
12+
13+
files = sorted(os.listdir(args.path))
14+
15+
16+
if not args.a:
17+
files = [f for f in files if not f.startswith(".")]
18+
19+
if args.one:
20+
for f in files:
21+
print(f)
22+
else:
23+
print(" ".join(files))

0 commit comments

Comments
 (0)