SysTutorials Forums QA How to test a file or directory exists in C++?

Tagged: 

How to test a path (a file or directory exists) in C++?

In Bash, the [ -f ] and [ -d ] tests can test whether a file or a directory exist. What are the corresponding C++ ways for these tests?

To test whether a file or dir (a path) exists, you may call stat() against the path and check its return value.

#include <sys/stat.h>

bool IsPathExist(const std::string &s)
{
  struct stat buffer;
  return (stat (s.c_str(), &buffer) == 0);
}
Reply To: How to test a file or directory exists in C++?
Your information:





<a href="" title="" rel="" target=""> <blockquote cite=""> <code> <pre> <em> <strong> <del datetime=""> <ul> <ol start=""> <li> <img src="" border="" alt="" height="" width="">

Please share if you like this post: