private static IEnumerable <string> EnumerateFileSystemIterator( LongPath path, string mask, bool enumerateDirectories, bool enumerateFiles) { if (string.IsNullOrEmpty(mask) || mask == ".") { mask = "*"; } string unprefixedPath = path.UnPrefixedPathString; WindowsNative.WIN32_FIND_DATA findData; using (FindFileHandle handle = BeginFind(Path.Combine(path.PathString, mask), out findData)) { if (handle == null) { yield break; } do { string fileName = findData.cFileName; if (IsDirectory(findData.dwFileAttributes)) { if (enumerateDirectories && IsRealFolder(fileName)) { yield return(Path.Combine(unprefixedPath, fileName)); } } else { if (enumerateFiles) { yield return(Path.Combine(unprefixedPath, fileName)); } } } while (WindowsNative.FindNextFile(handle, out findData)); int errorCode = Marshal.GetLastWin32Error(); if (errorCode != WindowsNative.ERROR_NO_MORE_FILES) { WindowsNative.HandleWindowsError(errorCode); } } }