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!
}

 

posted on 2019-11-01 09:32  liujx2019  阅读(158)  评论(0编辑  收藏  举报

导航