We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3e13fb5 commit c64c5ddCopy full SHA for c64c5dd
1 file changed
implement-shell-tools/ls/ls.py
@@ -0,0 +1,27 @@
1
+import sys
2
+import argparse
3
+import os
4
+
5
+parser = argparse.ArgumentParser(
6
+ prog="ls",
7
+ description="List all files name",
8
+)
9
10
+parser.add_argument("-1", dest="one", action="store_true", help="A new line for each file")
11
+parser.add_argument("-a", action="store_true", help="Show hidden files")
12
+parser.add_argument("path", nargs="?", default=".", help="The directory to list")
13
14
+args = parser.parse_args()
15
+path = args.path
16
17
+try:
18
+ files = os.listdir(path)
19
+ if not args.a:
20
+ files = [file for file in files if not file.startswith(".")]
21
+ if args.one:
22
+ print("\n".join(files))
23
+ else:
24
+ print(" ".join(files))
25
26
+except Exception as e:
27
+ print(f"Error reading {path}: {e}")
0 commit comments