我想使用getdirectories方法获取两个特定目录

时间:2014-03-30 05:02:36

标签: c# getdirectories

我想在C#中使用getdirectories方法获取两个特定目录?以下是获取一个目录的代码:

DirectoryInfo sourcefolder = new DirectoryInfo(ConfigurationManager.AppSettings["SourceLocation"].ToString());s
DirectoryInfo[] sourceRreportSubfolders = sourcefolder.GetDirectories("20120104");

使用上面的代码,我可以获得目录20120104,但是如果我想获得两个目录(20120104,20130302)呢?

1 个答案:

答案 0 :(得分:1)

var location = ConfigurationManager.AppSettings["SourceLocation"].ToString();
DirectoryInfo sourcefolder = new DirectoryInfo(location);
var sourceRreportSubfolders = sourcefolder.GetDirectories("20120104")
                             .Union(sourcefolder.GetDirectories("20130302"));
foreach (var dir in sourceRreportSubfolders)
{
    // Do something with dir
}