如何在C#中检查子目录 [英] how to check the sub dir's in C#

查看:56
本文介绍了如何在C#中检查子目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我试图基于文件名的模式"获取文件列表,但是下面的代码完成了工作,但没有查找子目录中的文件.任何有关如何在Sub Dir中查找文件格式的帮助也


Hi All,

I am trying to get the file list based on the "pattern" of the file name but the code below does the job but its not lookin the files in sub directories. Any help how to look the file patterns in Sub Dir''s also


var getfiles = new fileshare.Program();
string realname = "*main*";
string Location = "SVR01";
var fileList = getFiles.GetFileList(realname, Location);
var anymatch = fileList.Any();

if (anymatch) // Or possibly `if (fileList.Any())` if anymatch isn't 
              // really used anywhere else
    baseMeta();

foreach (var file in getfiles.GetFileList(realname,Location))
    getfiles.copytolocal(file.FullName);
 switch (Location)
    {
        case "SVR01":
            directory = @"\\SVR01\Dev";
        break;

        case "SVR02":
            directory = @"\\SVR02\Dev";
        break;

        case "SVR03":
            directory = @"\\SVR03\Prod");
        break;

        default: 
            throw new ArgumentOutOfRangeException();

    }

    DirectoryInfo di = null;
    try
    {
        di = new DirectoryInfo(directory);
    }
    catch(Exception ex)
    {
        Console.WriteLine(ex.Message);
        yield break;
    }

    foreach(var fi in di.EnumerateFiles(pattern))
        yield return fi;
}

推荐答案

朋友们,

此代码可以帮助您...


Hi friends,

this code may help u...


string[] folders = System.IO.Directory.GetDirectories(@"C:\My Sample Path\","*", System.IO.SearchOption.AllDirectories);




检查此站点....
http://www.progtalk.com/viewarticle.aspx?articleid=77 [ ^ ]




Check this site....
http://www.progtalk.com/viewarticle.aspx?articleid=77[^]


这篇关于如何在C#中检查子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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