Bitwise 'and' vs '=='
In this statement,
i could replace '&' with '==' i guess.
int DirectoryExists(char *path)
DWORD attr = GetFileAttributes(path);
if ( !(attr & FILE_ATTRIBUTE_DIRECTORY ))
Is there any reason to prefer one over the other?
You absolutely cannot replace & with ==.
Equals will check if the attributes only has the FILE_ATTRIBUTE_DIRECTORY bit set. The and operator will check if the FILE_ATTRIBUTE_DIRECTORY bit is set regardless of the other bits returned by GetFileAttributes().
Hmm, thanks for the reply Bithub!
"If the function fails, the return value is INVALID_FILE_ATTRIBUTES."
So there are other bits returned by GetFileAttributes().
I thought it was only the string INVALID_FILE_ATTRIBUTES.
There are several file attributes that can be set. You can see them all here.
Thank you very much, have a great day! :)