From 844297a61ed832a1e5276c17e6350b1480f3d954 Mon Sep 17 00:00:00 2001 From: Samuel Sloniker Date: Wed, 30 Nov 2022 20:34:25 +0000 Subject: [PATCH] Make `ls` more POSIX-like --- bin/ls.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/bin/ls.py b/bin/ls.py index e948689..578579b 100644 --- a/bin/ls.py +++ b/bin/ls.py @@ -3,8 +3,17 @@ import os def get_app_class(template): class App(template): def F_main(self): - for file in os.listdir(self.argv[1]): - print(file) + if len(self.argv) == 1: + directory = "." + else: + directory = self.argv[1] + + try: + for file in os.listdir(directory): + print(file) + except OSError as e: + print(str(e)) + self.exit() return App