Skip to content

Commit 37c7132

Browse files
Add -a flag to ls to show hidden files
1 parent ba64d28 commit 37c7132

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

  • implement-shell-tools/ls

implement-shell-tools/ls/ls.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@
88
)
99

1010
parser.add_argument("-1", dest="one_column", action="store_true", help="List one file per line")
11+
parser.add_argument("-a", "--all", action="store_true", help="Include hidden files")
1112
parser.add_argument("path", nargs='?', default=".", help="Directory to list (default: current directory)")
1213

1314
args = parser.parse_args()
1415

1516
# List directory contents
1617
files = os.listdir(args.path)
1718

18-
# Print each file
19+
# Filter out hidden files unless -a flag is used
20+
if not args.all:
21+
files = [f for f in files if not f.startswith('.')]
22+
1923
for file in files:
2024
print(file)

0 commit comments

Comments
 (0)