4

我的功能几乎是一个标准的搜索功能......我已经将它包含在下面。

在函数中,我有 1 行代码负责清除 Repart NTFS 点。

if (attributes.ToString().IndexOf("ReparsePoint") == -1)

问题是现在我收到一个错误 Access to the path 'c:\System Volume Information' is denied.

我调试了代码,该目录在运行时的唯一属性是:

  System.IO.FileAttributes.Hidden 
| System.IO.FileAttributes.System 
| System.IO.FileAttributes.Directory

我正在 Windows 2008 服务器机器上执行此代码,有什么想法可以解决此故障吗?

public void DirSearch(string sDir)
{
    foreach (string d in Directory.GetDirectories(sDir))
    {
        DirectoryInfo dInfo = new DirectoryInfo(d);
        FileAttributes  attributes = dInfo.Attributes;
        if (attributes.ToString().IndexOf("ReparsePoint") == -1)
        {
            foreach (string f in Directory.GetFiles(d, searchString))
            {
                //lstFilesFound.Items.Add(f);
                ListViewItem lvi;
                ListViewItem.ListViewSubItem lvsi;
                lvi = new ListViewItem();
                lvi.Text = f;
                lvi.ImageIndex = 1;
                lvi.Tag = "tag";
                lvsi = new ListViewItem.ListViewSubItem();
                lvsi.Text = "sub bugger";
                lvi.SubItems.Add(lvsi);

                lvsi = new ListViewItem.ListViewSubItem();
                lvsi.Text = d;//"C:\\Users\\Administrator\\Downloads\\MediaMonkey.GOLD.EDITION.v.3.0.2.1134.[Darkside].[Demonoid].[Grim.Reaper]";
                lvi.SubItems.Add(lvsi);

                listView1.Items.Add(lvi);
            }
            DirSearch(d);
        }
    }
}
4

4 回答 4

18

我不确定问题的答案是什么,但更改您的属性检查以使用正确的按位运算!

if (attributes.ToString().IndexOf("ReparsePoint") == -1)

... 更正确地写为 ...

if ((attributes & FileAttributes.ReparsePoint) == 0)
于 2008-12-01T22:04:24.140 回答
3

除了 SYSTEM 帐户,没有人有权访问系统卷信息。所以要么更改目录的权限。或者更好地捕获异常并继续。

于 2008-12-01T22:04:59.363 回答
1

也许这篇文章可以帮助你(他们解释了如何访问这个文件夹):

http://support.microsoft.com/kb/309531

绝望的解决方案是try-catch。

于 2008-12-01T22:08:38.640 回答
0

一旦你获得了过去的权限,并且真的想测试连接点,这个类通过使用 DeviceIoControl kernel32 调用和分析重解析点来提供连接点的测试、创建和删除。

于 2018-06-27T23:06:15.037 回答