26_listdircpp17.cpp 379 B

12345678910111213141516171819202122232425262728
  1. #include <iostream>
  2. #include <filesystem>
  3. using namespace std;
  4. using namespace std::filesystem;
  5. int main()
  6. {
  7. path p("/sdcard");
  8. if (!exists(p))
  9. {
  10. cout << p << " not found" << endl;
  11. return 1;
  12. }
  13. if (!is_directory(p))
  14. {
  15. cout << p << " is not a directory" << endl;
  16. return 1;
  17. }
  18. for (auto &d : directory_iterator(p))
  19. {
  20. cout << d.path() << endl;
  21. }
  22. return 0;
  23. }