From be6b044883e65e864337abd5b1e3520ceb169321 Mon Sep 17 00:00:00 2001 From: Samuel Sloniker Date: Wed, 30 Nov 2022 20:50:43 +0000 Subject: [PATCH] Handle regular files properly in ls --- bin/ls.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/bin/ls.py b/bin/ls.py index 578579b..29a281a 100644 --- a/bin/ls.py +++ b/bin/ls.py @@ -4,15 +4,19 @@ def get_app_class(template): class App(template): def F_main(self): if len(self.argv) == 1: - directory = "." + path = "." else: - directory = self.argv[1] + path = self.argv[1] try: - for file in os.listdir(directory): + for file in os.listdir(path): print(file) except OSError as e: - print(str(e)) + try: + os.stat(path) + print(path) + except OSError: + print(f"ls: cannot access '{path}': No such file or directory") self.exit()