C#文件权限排除 [英] C# File Permission Exclusion

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

问题描述

  DriveInfo [] dDrives = DriveInfo.GetDrives(); 
foreach(DriveInfo dDrive in dDrives)
{
try
{
string sDrive = dDrive.ToString();
string [] sSearch = Directory.GetFiles(sDrive,sFile,SearchOption.AllDirectories);
foreach(sSearch中的字符串sResult)
{
textBox2.Text = sResult + Environment.NewLine;





$ b code $ pre

当遇到由于权限而无法访问的文件时,它会触发并结束。我需要做的是,如果遇到无法访问的文件,请返回到try块并继续搜索。任何帮助非常感谢,谢谢!

解决方案

不正确。



请参阅: UnauthorizedAccessException无法解析Directory.GetFiles失败对于你的问题一些建议的解决方案。


I was wondering if there is a way to solve the issue I have with this code:

DriveInfo[] dDrives = DriveInfo.GetDrives();
foreach(DriveInfo dDrive in dDrives)
{
    try
    {
        string sDrive = dDrive.ToString();
        string[] sSearch = Directory.GetFiles(sDrive, sFile, SearchOption.AllDirectories);
        foreach(string sResult in sSearch)
        {
            textBox2.Text = sResult + Environment.NewLine;
        }
    }
    catch
    {
    }
}

When it comes across a file that isn't accessible because of permissions, it will goto the catch and end. What I need it to do is if it comes across a file it can't access, go back to the try block and continue searching. Any help is much appreciated, thanks!

解决方案

EDIT: Removed original answer as incorrect.

See: UnauthorizedAccessException cannot resolve Directory.GetFiles failure for some suggested resolutions to your problem.

这篇关于C#文件权限排除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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