本文整理汇总了C#中FindOperation.GetNextResult方法的典型用法代码示例。如果您正苦于以下问题:C# FindOperation.GetNextResult方法的具体用法?C# FindOperation.GetNextResult怎么用?C# FindOperation.GetNextResult使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FindOperation
的用法示例。
在下文中一共展示了FindOperation.GetNextResult方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EnumerateChildrenInternal
internal static IEnumerable<IFileSystemInformation> EnumerateChildrenInternal(
string directory,
ChildType childType,
string searchPattern,
System.IO.SearchOption searchOption,
FileAttributes excludeAttributes,
IFileService fileService)
{
// We want to be able to see all files as we recurse and open new find handles (that might be over MAX_PATH).
// We've already normalized our base directory.
string extendedDirectory = Paths.AddExtendedPrefix(directory);
// The assertion here is that we want to find files that match the desired pattern in all subdirectories, even if the
// subdirectories themselves don't match the pattern. That requires two passes to avoid overallocating for directories
// with a large number of files.
// First look for items that match the given search pattern in the current directory
using (FindOperation findOperation = new FindOperation(Paths.Combine(extendedDirectory, searchPattern)))
{
FindResult findResult;
while ((findResult = findOperation.GetNextResult()) != null)
{
bool isDirectory = (findResult.Attributes & FileAttributes.FILE_ATTRIBUTE_DIRECTORY) == FileAttributes.FILE_ATTRIBUTE_DIRECTORY;
if ((findResult.Attributes & excludeAttributes) == 0
&& findResult.FileName != "."
&& findResult.FileName != ".."
&& ((isDirectory && childType == ChildType.Directory)
|| (!isDirectory && childType == ChildType.File)))
{
yield return FileSystemInformation.Create(findResult, directory, fileService);
}
}
}
if (searchOption != System.IO.SearchOption.AllDirectories) yield break;
// Now recurse into each subdirectory
using (FindOperation findOperation = new FindOperation(Paths.Combine(extendedDirectory, "*"), directoriesOnly: true))
{
FindResult findResult;
while ((findResult = findOperation.GetNextResult()) != null)
{
// Unfortunately there is no guarantee that the API will return only directories even if we ask for it
bool isDirectory = (findResult.Attributes & FileAttributes.FILE_ATTRIBUTE_DIRECTORY) == FileAttributes.FILE_ATTRIBUTE_DIRECTORY;
if ((findResult.Attributes & excludeAttributes) == 0
&& isDirectory
&& findResult.FileName != "."
&& findResult.FileName != "..")
{
foreach (var child in EnumerateChildrenInternal(Paths.Combine(directory, findResult.FileName), childType, searchPattern,
searchOption, excludeAttributes, fileService))
{
yield return child;
}
}
}
}
}