c++ - How to find out if a folder exists and how to create a folder? -
i'm trying create folder if doesn't exist. i'm using windows , not interested on code working in other platforms.
never mind, found solution. having inclusion problem. answer is:
#include <io.h> // access(). #include <sys/types.h> // stat(). #include <sys/stat.h> // stat(). #include <iostream> #include <string> using namespace std; string strpath; cout << "enter directory check: "; cin >> strpath; if ( access( strpath.c_str(), 0 ) == 0 ) { struct stat status; stat( strpath.c_str(), &status ); if ( status.st_mode & s_ifdir ) { cout << "the directory exists." << endl; } else { cout << "the path entered file." << endl; } } else { cout << "path doesn't exist." << endl; }
the posix-compatible call mkdir. it silently fails when directory exists.
if using windows api, createdirectory more appropriate.
Comments
Post a Comment