允许访问计算机上的每个文件

时间:2014-07-24 21:41:05

标签: file c#-4.0 search access-denied documents

我一直收到“无法访问文档和设置”问题。我已经尝试将它编码到目录上的某些标志将停止这个,但我然后没有得到计算机上的所有文件夹.....我的计划是使用Directory.GetFiles()方法一旦我拥有列表中的文件夹。但是,我得到的只是Drive名称....任何想法?

我用它来检查我是否可以使用目录:

    public static bool IsEmptyDirectory(string path)
    {
        DirectoryInfo info = new DirectoryInfo(path);

        if ((info.Attributes & FileAttributes.ReparsePoint) != 0)
        {
            return true;//Not allowed to read, errors out
        }//if ((info.Attributes & FileAttributes.ReparsePoint) != 0)
        else if ((info.Attributes & FileAttributes.Hidden) != 0)
        {
            return true;//Not allowed to read, errors out
        }//else if ((info.Attributes & FileAttributes.Hidden) != 0)
        else if ((info.Attributes & FileAttributes.System) != 0)
        {
            return true;//Not allowed to read, errors out
        }//else if ((info.Attributes & FileAttributes.System) != 0)
        else
        {
            return false;//Should be safe to read
        }//else
    }//public static bool IsEmptyDirectory(string path)

以下是Button Click上发生的情况:             List FileList = new List();             string Directory =“”;

        foreach (var drive in DriveInfo.GetDrives())
        {
            Directory = drive.Name;
            SearchDir(ref FileList, Directory);
        }//foreach (var drive in DriveInfo.GetDrives())

        foreach (string folderfound in FileList)
        {
            lstDupePics.Items.Add(folderfound);
        }

这是SearchDir方法:

    public void SearchDir(ref List<string> FileList, string directory)
    {
        FileList.Add(directory);

        if (!clsFunctions.IsEmptyDirectory(directory))
        {
            string[] sfolderList = Directory.GetDirectories(directory);

            foreach (string sfolder in sfolderList)
            {
                SearchDir(ref FileList, sfolder);
            }
        }
    }

也许我只是让这复杂化......

0 个答案:

没有答案