posix_dir_files.cpp 672 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include<__vic/posix/dir_files.h>
  2. #include<cassert>
  3. #include<iostream>
  4. #include<exception>
  5. namespace tests {
  6. void print(__vic::posix::dir_files &files)
  7. {
  8. assert(files.is_open());
  9. while(const char *f = files.next())
  10. std::cout << f << '\n';
  11. }
  12. void run()
  13. {
  14. std::cout << "All files:\n";
  15. __vic::posix::dir_files files(".");
  16. print(files);
  17. std::cout << "\n*.cpp files:\n";
  18. __vic::posix::dir_files cpp_files(".", "*.cpp");
  19. print(cpp_files);
  20. }
  21. } // namespace
  22. int main()
  23. {
  24. try
  25. {
  26. tests::run();
  27. return 0;
  28. }
  29. catch(const std::exception &ex)
  30. {
  31. std::cerr << ex.what() << '\n';
  32. }
  33. return 1;
  34. }