解释dwFileAttributes [英] Explain dwFileAttributes

查看:212
本文介绍了解释dwFileAttributes的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我尝试阅读包含文件的子目录.使用调试器,我看到正确的文件名,但是"dwFileAttributes"的值是48,这是错误的,据我所知应该是16.我试过其他目录,它们很好.

您能帮我理解为什么为dwFileAttributes 分配48而不是16的原因吗?

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?

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


在此先感谢
MH


Thanks in advance
M.H

推荐答案

dwFileAttributes可以保留零个,一个或多个标志,并使用运算符将它们组合在一起. >
对于您的情况dwFileAttributes = 48 = FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_DIRECTORY.

如果要检查条目是文件还是文件夹(如代码片段中所示),则应按以下所示进行操作:

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:

WIN32_FIND_DATA FileData
handle = FindFirstFile(path, &FileData);
if ((FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0)
{
   // It's a directory...
}


您应以十六进制格式查看它们,因为这样可以使内容更清晰. dwFileAttributes是位掩码,因此值48以十六进制为0x30,这是两位设置0x20和0x10.快速浏览定义 [
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.


这篇关于解释dwFileAttributes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆