-
-
Notifications
You must be signed in to change notification settings - Fork 92
Expand file tree
/
Copy pathlsFile.py
More file actions
31 lines (21 loc) · 675 Bytes
/
lsFile.py
File metadata and controls
31 lines (21 loc) · 675 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
import sys
import os
def main():
argv = sys.argv[1:]
dash = [arg for arg in argv if arg.startswith('-')]
paths = [arg for arg in argv if not arg.startswith('-')]
show_all = '-a' in dash
target_dir = paths[0] if paths else '.'
try:
entries = os.listdir(target_dir)
except FileNotFoundError:
print(f"ls: {target_dir}: No such file or directory", file=sys.stderr)
sys.exit(1)
if show_all:
result = ['.', '..'] + entries
else:
result = [e for e in entries if not e.startswith('.')]
for entry in result:
print(entry)
if __name__ == "__main__":
main()