1 // Licensed to the .NET Foundation under one or more agreements. 2 // The .NET Foundation licenses this file to you under the MIT license. 3 // See the LICENSE file in the project root for more information. 4 5 using Microsoft.Win32.SafeHandles; 6 using System; 7 using System.IO; 8 using System.Runtime.InteropServices; 9 10 internal partial class Interop 11 { 12 internal partial class Kernel32 13 { 14 /// <summary> 15 /// WARNING: This method does not implicitly handle long paths. Use FindFirstFile. 16 /// </summary> 17 [DllImport(Libraries.Kernel32, EntryPoint = "FindFirstFileExW", SetLastError = true, CharSet = CharSet.Unicode)] FindFirstFileExPrivate(string lpFileName, FINDEX_INFO_LEVELS fInfoLevelId, ref WIN32_FIND_DATA lpFindFileData, FINDEX_SEARCH_OPS fSearchOp, IntPtr lpSearchFilter, int dwAdditionalFlags)18 private static extern SafeFindHandle FindFirstFileExPrivate(string lpFileName, FINDEX_INFO_LEVELS fInfoLevelId, ref WIN32_FIND_DATA lpFindFileData, FINDEX_SEARCH_OPS fSearchOp, IntPtr lpSearchFilter, int dwAdditionalFlags); 19 FindFirstFile(string fileName, ref WIN32_FIND_DATA data)20 internal static SafeFindHandle FindFirstFile(string fileName, ref WIN32_FIND_DATA data) 21 { 22 fileName = PathInternal.EnsureExtendedPrefixOverMaxPath(fileName); 23 24 // use FindExInfoBasic since we don't care about short name and it has better perf 25 return FindFirstFileExPrivate(fileName, FINDEX_INFO_LEVELS.FindExInfoBasic, ref data, FINDEX_SEARCH_OPS.FindExSearchNameMatch, IntPtr.Zero, 0); 26 } 27 28 internal enum FINDEX_INFO_LEVELS : uint 29 { 30 FindExInfoStandard = 0x0u, 31 FindExInfoBasic = 0x1u, 32 FindExInfoMaxInfoLevel = 0x2u, 33 } 34 35 internal enum FINDEX_SEARCH_OPS : uint 36 { 37 FindExSearchNameMatch = 0x0u, 38 FindExSearchLimitToDirectories = 0x1u, 39 FindExSearchLimitToDevices = 0x2u, 40 FindExSearchMaxSearchOp = 0x3u, 41 } 42 } 43 } 44