在遍历目录的时候出现“对路径"E:\System Volume Information"的访问被拒绝“这个问题。
百度了一下说是,某些路径是不可访问的,比如这个System Volume Information,每个磁盘下都有。
最后采用了,把隐藏文件过滤掉的方法:
private static bool IsSystemHidden(DirectoryInfo dirInfo)
{
if (dirInfo.Parent == null)
{
return false;
}
string attributes = dirInfo.Attributes.ToString();
if (attributes.IndexOf("Hidden") > -1 && attributes.IndexOf("System") > -1)
{
return true;
}
return false;
}
这个方法是别人写的,亲测可用。
在进行目录遍历时遇到无法访问'E:\System Volume Information'的问题。该路径是系统隐藏的,通常不允许直接访问。通过编写IsSystemHidden方法,检查并过滤掉具有隐藏和系统属性的目录,从而避免访问被拒绝的错误。这种方法已验证有效。
1万+





