Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if directory exist using C++ and winAPI [duplicate]

How do I check whether a directory exists using C++ and windows API?

like image 444
MaSmi Avatar asked Nov 22 '11 21:11

MaSmi


2 Answers

Here is a simple function which does exactly this :

#include <windows.h> #include <string>  bool dirExists(const std::string& dirName_in) {   DWORD ftyp = GetFileAttributesA(dirName_in.c_str());   if (ftyp == INVALID_FILE_ATTRIBUTES)     return false;  //something is wrong with your path!    if (ftyp & FILE_ATTRIBUTE_DIRECTORY)     return true;   // this is a directory!    return false;    // this is not a directory! } 
like image 108
FailedDev Avatar answered Oct 07 '22 20:10

FailedDev


If linking to the shell Lightweight API (shlwapi.dll) is ok for you, you can use the PathIsDirectory function

like image 39
Simon Mourier Avatar answered Oct 07 '22 20:10

Simon Mourier