Skip to content

Commit 3d571eb

Browse files
committed
implementing ls -1
1 parent fc93e92 commit 3d571eb

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

  • implement-shell-tools/ls

implement-shell-tools/ls/ls.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import os
2+
import argparse
3+
4+
parser=argparse.ArgumentParser(prog="cat",usage="implement a simple ls python")
5+
parser.add_argument("-1",dest="one",action="store_true")
6+
parser.add_argument("-a",action="store_true")
7+
parser.add_argument("path",nargs="*",help="path to list files")
8+
args=parser.parse_args()
9+
10+
paths=args.path
11+
if len(paths)==0 : paths=["."]
12+
13+
for path in paths :
14+
files_list=os.listdir(path)
15+
files_list.sort(key=str.lower)
16+
if args.one :
17+
for item in files_list :
18+
print(item)

0 commit comments

Comments
 (0)