-
-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathls.py
More file actions
40 lines (26 loc) · 964 Bytes
/
ls.py
File metadata and controls
40 lines (26 loc) · 964 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
import argparse
import os
parser = argparse.ArgumentParser(
prog="list-files-in-directory",
description="List all files and directories in a directory",
)
parser.add_argument("-1", "--one", dest="one", help="Output one entry per line", action="store_true")
parser.add_argument("-a", help="List all files & directories, including hidden ones", action="store_true")
parser.add_argument("paths", nargs="*", default=["."], help="The file path to read from")
args = parser.parse_args()
for path in args.paths:
if os.path.isdir(path):
items = os.listdir(path)
if args.a:
items = ['.', '..'] + items
else:
items = [item for item in items if not item.startswith(".")]
for item in items:
if args.one:
print(item)
else:
print(item, end=" ")
if not args.one:
print()
else:
print(path)