如何检查目录是否存在使用C ++和winAPI [英] How to check if directory exist using C++ and winAPI

查看:165
本文介绍了如何检查目录是否存在使用C ++和winAPI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

如何检查C中的Windows目录是否存在?

如何使用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!
}

这篇关于如何检查目录是否存在使用C ++和winAPI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆