如何使用C ++和winAPI检查目录是否存在
问题描述:
如何使用C ++和Windows API检查目录是否存在?
How do I check whether a directory exists using C++ and windows API?
答
很好,我们都在 n0obs 在某个时间点。询问没有问题。这里是一个简单的函数,它完全如此:
well we were all n0obs at some point in time. No problem in asking. 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!
}