Windows 7 64-bit, compiling with mingw. I’m trying to test whether a given path is a directory using GetFileAttributesA in the Windows headers. The constant for something being a directory is 16. For some reason, though, it’s returning 17. My code looks like this:
#include <iostream>
#include <windows.h>
void dir_exists(std::string dir_path)
{
DWORD f_attrib = GetFileAttributesA(dir_path.c_str());
std::cout << "Current: " << f_attrib << std::endl <<
"Wanted: " <<
FILE_ATTRIBUTE_DIRECTORY << std::endl;
}
int main()
{
dir_exists("C:\\Users\\");
return 0;
}
When I run this, the output is:
Current: 17
Wanted: 16
Current should be returning 16, here. As I said in the topic, I can’t even find any mention of what 17 means in the documentation.
GetFileAttributesreturns a bitmask, the valid values for which are listed here: File Attribute Constants.17 == 0x11, so that means the return value is
FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_DIRECTORY.If you just want to detect whether your path points to a directory, mask the return value with
FILE_ATTRIBUTE_DIRECTORYand see if it’s non-zero: