How do I check whether a directory exists using C++ and windows API?
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! }
If linking to the shell Lightweight API (shlwapi.dll) is ok for you, you can use the PathIsDirectory function
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With