/// <summary>Enumerate files in directory.</summary> static IEnumerable <WIN32_FIND_DATA> findImpl(string path, string searchPattern) { string fileName = Path.Combine(path, searchPattern); WIN32_FIND_DATA fd; using (SafeSearchHandle h = NativeMethods.FindFirstFile(fileName, out fd)) { if (h.IsInvalid) { throwIfNeeded("FindFirstFileExW failed"); yield break; } do { if (fd.cFileName == "." || fd.cFileName == "..") { continue; } yield return(fd); }while(NativeMethods.FindNextFileW(h, out fd)); throwIfNeeded("FindNextFileW failed"); yield break; } }
public static extern bool FindNextFileW(SafeSearchHandle hFindFile, out WIN32_FIND_DATA lpFindFileData);