我有这样的循环:
foreach (DirectoryInfo dir in downloadedMessageInfo.GetDirectories())
{
if (dir.Attributes != FileAttributes.Hidden)
{
dir.Delete(true);
}
}
我怎样才能正确地跳过所有隐藏的目录?
How can I correctly skip all hidden directories?
更改您的if语句:
Change your if statement to:
if ((dir.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden)
您需要使用掩码,因为属性是一个标志枚举。它可以有多个值,让隐藏的文件夹可能被隐藏,另一个标志。上述语法将检查这个正确。
You need to use the bitmask since Attributes is a flag enum. It can have multiple values, so hidden folders may be hidden AND another flag. The above syntax will check for this correctly.
上一篇:排序列表与SortedDictionary与排序()列表、SortedDictionary
下一篇:发送使用Cookie HttpCookieCollection和的CookieContainerCookie、HttpCookieCollection、CookieContainer