Jump to content
  • Advertisement
Sign in to follow this  

WIN32_FIND_DATA Question

This topic is 4882 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

One of the members of the struct WIN32_FIND_DATA is a DWORD dwFileAttributes, which can be one or more values. How can I test if one of the values is true? For example, how would I test if a file is a directory? You can't use == since it can be more than one value. [Edited by - v0dKA on January 8, 2005 4:29:56 PM]

Share this post


Link to post
Share on other sites
Advertisement
You want to use the bitwise AND operator (&) like so:

WIN32_FIND_DATA fd;
if ( fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) {
// Is a directory
}
else {
// Is not
}




[edit] You might want to check out bitstrings and bitmasks.
The reason this works is that ANDing the two together produces a non-zero value if the one of the attributes is a directory.
Say you have the following bitstring:
  11010110
and you wanted to check that the second bit was true (1), you would AND it with
  00000010
which would result precisely with 00000010, which is non-zero (TRUE). (Remeber that only TRUE AND TRUE results in TRUE)

If the original bitstring had been 11010100, then ANDing it with 00000010 would have resulted in 00000000 (FALSE)

Hope that helps.

Share this post


Link to post
Share on other sites
Yes, it does. And just to make sure, if, let's say, the second bit indeed is the directory bit, then FILE_ATTRIBUTE_DIRECTORY would be #defined 00000010?

Also, what do the files "." and ".." represent? I know one of them is the parent directory, but which one, and what's the other one?

Share this post


Link to post
Share on other sites
Well, actually it is defined as 0x00000002, because it's in hex (I don't know that there are "binary literals" in C++, someone enlighten me if there is), but that is the same as 000...000010, yes.

"." means current directory
".." means parent directory (directory above)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!