/tutorial/directory/example1.e

http://github.com/tybor/Liberty · Specman e · 70 lines · 54 code · 7 blank · 9 comment · 3 complexity · 5df469a6c75f0ae74b63d738d5ebe9a0 MD5 · raw file

  1. class EXAMPLE1
  2. --
  3. -- This example shows how to list the contents of a directory
  4. -- using class DIRECTORY.
  5. -- When no argument is given in the command line, the current working
  6. -- directory is listed.
  7. --
  8. -- compile -o run_it example1
  9. -- run_it some_directory_path
  10. --
  11. insert
  12. ARGUMENTS
  13. create {ANY}
  14. make
  15. feature {}
  16. make
  17. local
  18. directory: DIRECTORY; some_path: STRING
  19. do
  20. if argument_count > 1 then
  21. io.put_string("usage : example1 [<some_path>]%N")
  22. elseif argument_count = 1 then
  23. some_path := argument(1)
  24. create directory.scan(some_path)
  25. if directory.exists then
  26. list_directory(directory)
  27. else
  28. io.put_string("Unable to open directory %"")
  29. io.put_string(some_path)
  30. io.put_string("%".%N")
  31. end
  32. else
  33. io.put_string("Scanning current working directory.%N")
  34. create directory.scan_current_working_directory
  35. list_directory(directory)
  36. end
  37. end
  38. list_directory (directory: DIRECTORY)
  39. local
  40. i: INTEGER
  41. do
  42. io.put_string("Printing content of %"")
  43. io.put_string(directory.path)
  44. io.put_string("%".%N")
  45. io.put_integer(directory.count)
  46. io.put_string(" item(s) found:%N")
  47. from
  48. i := directory.lower
  49. until
  50. i > directory.count
  51. loop
  52. io.put_character('%T')
  53. if directory.file_at(i).is_directory then
  54. io.put_string(once "directory ")
  55. else
  56. io.put_string(once "file ")
  57. end
  58. io.put_string(directory.item(i))
  59. io.put_character('%N')
  60. i := i + 1
  61. end
  62. end
  63. end -- class EXAMPLE1