有没有办法让IEnumerable<FileInfo>
退出Directory.EnumerateDirectories(..)
?
我的方法看起来像这样。
public static IEnumerable<String> EnumerateFiles(String path, String searchPattern, SearchOption searchOpt)
{
try
{
IEnumerable<string> dirFiles = Enumerable.Empty<String>();
if (searchOpt == SearchOption.AllDirectories)
{
dirFiles = Directory.EnumerateDirectories(path)
.SelectMany(x => EnumerateFiles(x, searchPattern, searchOpt));
}
return dirFiles.Concat(Directory.EnumerateFiles(path, searchPattern));
}
catch (UnauthorizedAccessException ex)
{
return Enumerable.Empty<String>();
}
}
我也想实施:
public static IEnumerable<FileInfo> EnumerateFiles(String path, String searchPattern, SearchOption searchOpt)
{
//...code
}