You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 
 
 
 

43 lines
942 B

  1. import sys
  2. import os
  3. def parse_args(args):
  4. options = Options()
  5. if "-l" in args:
  6. options.show_modification_time= True
  7. return options
  8. class Options:
  9. def __init__(self):
  10. self.show_modification_time = False
  11. class Entry:
  12. def __init__(self,name):
  13. self.name=name
  14. self.is_directory=False
  15. self.mtime=0
  16. def get_entries():
  17. names = os.listdir(".")
  18. for name in names:
  19. entry = Entry(name)
  20. entry.mtime = os.stat(name).st_mtime
  21. yield entry
  22. def list_entries(entries,options):
  23. for entry in entries:
  24. if options.show_modification_time :
  25. yield f"{entry.name} {entry.mtime}"
  26. else:
  27. yield entry.name
  28. def main():
  29. options=parse_args(sys.argv)
  30. entries = get_entries()
  31. lines = list_entries(entries,options)
  32. for line in lines:
  33. print(line)
  34. if __name__=="__main__":
  35. main()