check if directory exists cpp

Solutions on MaxInterview for check if directory exists cpp by the best coders in the world

showing results for - "check if directory exists cpp"
Juan Diego
30 Jul 2018
1#include <sys/stat.h>
2
3bool IsPathExist(const std::string &s)
4{
5  struct stat buffer;
6  return (stat (s.c_str(), &buffer) == 0);
7}
8
Christian
19 Sep 2020
1#include <sys/stat.h>
2
3int main() {
4	struct stat buffer;
5    std::string string = "Hello";
6    
7    if (stat(&string.c_str(), &buffer) != 0) {
8    	std::cout << "'Hello' directory doesn't exist!";
9    } else {
10    	std::cout << "'Hello' directory exists!";
11    }
12}