code_junkie

How do i check if a file is a regular file in C++?

Nov 12th, 2011
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. DIR *dp;
  2. struct dirent *dirp;
  3.  
  4. while ((dirp = readdir(dp)) != NULL) {
  5. if ( isFile(dirp)) {
  6. cout << "IS A FILE!" << endl;
  7. i++;
  8. }
  9.  
  10. #include <boost/filesystem/path.hpp>
  11. #include <boost/filesystem/operations.hpp>
  12. #include <iostream>
  13.  
  14. int main() {
  15. using namespace boost::filesystem;
  16.  
  17. path p("/bin/bash");
  18. if(is_regular_file(p)) {
  19. std::cout << "exists and is regular file" << std::endl;
  20. }
  21. }
  22.  
  23. while ((dirp = readdir(dp)) != NULL) {
  24. if (!S_ISDIR(dirp->d_type)) {
  25. ...
  26. i++;
  27. }
  28. }
Add Comment
Please, Sign In to add comment