Handle regular files properly in ls
This commit is contained in:
parent
844297a61e
commit
be6b044883
12
bin/ls.py
12
bin/ls.py
|
@ -4,15 +4,19 @@ def get_app_class(template):
|
||||||
class App(template):
|
class App(template):
|
||||||
def F_main(self):
|
def F_main(self):
|
||||||
if len(self.argv) == 1:
|
if len(self.argv) == 1:
|
||||||
directory = "."
|
path = "."
|
||||||
else:
|
else:
|
||||||
directory = self.argv[1]
|
path = self.argv[1]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for file in os.listdir(directory):
|
for file in os.listdir(path):
|
||||||
print(file)
|
print(file)
|
||||||
except OSError as e:
|
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()
|
self.exit()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user