33_listdir.cpp 432 B

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