Click here to Skip to main content
15,891,653 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I try to read a sub direcory which cointains files. With debugger I see the right file name but "dwFileAttributes" has value 48 which is wrong, it should be 16 what I understand. I have tried with other directory and they are fine.

Could you please help me to understand why dwFileAttributes is assigned 48 and not 16?

C++
WIN32_FIND_DATA FileData
handle  =   FindFirstFile(path,&FileData);
if(FileData.dwFileAttributes  == 16)
{
}

Thanks in advance
M.H
Posted
Updated 27-Oct-10 1:57am
v2

The dwFileAttributes could keep zero, one or more flags and they are combined together using the or operator.

In your case dwFileAttributes = 48 = FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_DIRECTORY.

If you want to check if an entry is a file or a folder, as in your code snippet, you should do it as shown below:

C++
WIN32_FIND_DATA FileData
handle = FindFirstFile(path, &FileData);
if ((FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0)
{
   // It's a directory...
}
 
Share this answer
 
v3
Comments
Nish Nishant 27-Oct-10 10:27am    
Voted 5, proposed as answer.
merh 27-Oct-10 10:38am    
Thanks a lot
M.H
Dalek Dave 27-Oct-10 10:57am    
Good call.
You should view them in HEX format as that will make it clearer. dwFileAttributes is a bit mask so the value 48 is 0x30 in hexadecimal, which is the two bit settings 0x20 and 0x10. A quick glance at the definition[^] in MSDN will confirm what each bit signifies.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900