-
-
Notifications
You must be signed in to change notification settings - Fork 92
Expand file tree
/
Copy pathls.py
More file actions
23 lines (15 loc) · 647 Bytes
/
ls.py
File metadata and controls
23 lines (15 loc) · 647 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import argparse
import os
parser = argparse.ArgumentParser(description="Display one file per line from ls directory")
parser.add_argument("-1", dest="one", action="store_true", help="List one file per line")
parser.add_argument("-a", action="store_true", help="Include hidden files (those starting with .)")
parser.add_argument("path", nargs="?", default=".", help="The directory to list (default: current directory)")
args = parser.parse_args()
files = sorted(os.listdir(args.path))
if not args.a:
files = [f for f in files if not f.startswith(".")]
if args.one:
for f in files:
print(f)
else:
print(" ".join(files))