Checking the Directory (WINDOWS)

Asked

Viewed 63 times

3

How do I check if a directory exists using C++ and Windows API?

1 answer

4


There is the function GetFileAttributesA that retrieves system attributes for a specified directory or file.

More information -> MSDN

Here a simple function that does exactly what you want:

bool HYPNOS_DIR_VALIDATE(const std::string& hypnos_dirNAME)
{
  DWORD hypnos_ftyp = GetFileAttributesA(hypnos_dirNAME.c_str());
  if (hypnos_ftyp == INVALID_FILE_ATTRIBUTES)
    return false;  // algo de errado com o path

  if (hypnos_ftyp & FILE_ATTRIBUTE_DIRECTORY)
    return true;   // É um diretório!

  return false;    // Não é um diretório.
}
  • 1

    What is the "Hypnos"?

  • Dude... kkkkk is just a project of mine.. :)

  • 1

    Okay! Good luck with your project. Have fun!

  • Hahaha, thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.