-
-
Notifications
You must be signed in to change notification settings - Fork 92
Expand file tree
/
Copy pathls.py
More file actions
41 lines (32 loc) · 716 Bytes
/
Copy pathls.py
File metadata and controls
41 lines (32 loc) · 716 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import argparse
import os
parser = argparse.ArgumentParser(
prog="ls",
description="List directory content",
)
parser.add_argument(
"-1",
action="store_true",
dest="one",
help="List one file per line",
)
parser.add_argument(
"-a",
action="store_true",
help="Do not ignore entries starting with .",
)
parser.add_argument(
"path",
nargs="?",
default=".",
help="The directory to list",
)
args = parser.parse_args()
items = os.listdir(args.path)
if args.a:
items = [".", ".."] + items
else:
items = [item for item in items if not item.startswith(".")]
items = sorted(items, key=lambda item: item.lstrip(".").lower())
for item in items:
print(item)