fibonaccios/bin/ls.py

25 lines
690 B
Python
Raw Normal View History

2022-11-29 19:46:03 -08:00
import os
2022-11-30 19:33:05 -08:00
import console
2022-11-29 19:46:03 -08:00
def get_app_class(template):
class App(template):
def F_main(self):
2022-11-30 12:34:25 -08:00
if len(self.argv) == 1:
2022-11-30 12:50:43 -08:00
path = "."
2022-11-30 12:34:25 -08:00
else:
2022-11-30 12:50:43 -08:00
path = self.argv[1]
2022-11-30 12:34:25 -08:00
try:
2022-11-30 12:50:43 -08:00
for file in os.listdir(path):
2022-11-30 19:33:05 -08:00
console.write_str(self.console, file + "\n")
2022-11-30 12:34:25 -08:00
except OSError as e:
2022-11-30 12:50:43 -08:00
try:
os.stat(path)
2022-11-30 19:33:05 -08:00
console.write_str(self.console, path + "\n")
2022-11-30 12:50:43 -08:00
except OSError:
2022-11-30 19:33:05 -08:00
console.write_str(self.console, f"ls: cannot access '{path}': No such file or directory\n")
2022-11-30 12:34:25 -08:00
2022-11-29 19:46:03 -08:00
self.exit()
return App