How to check if directory exist using C++ and winAPI
如果看文件夹是否存在,必须看返回值是不是 INVALID_FILE_ATTRIBUTES
#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! }