Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than kernel32, prefix the name with the module name and a period.
FindFirstFile (kernel32)
.
C# Signature:
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern IntPtr FindFirstFileEx(
string lpFileName,
FINDEX_INFO_LEVELS fInfoLevelId,
out WIN32_FIND_DATA lpFindFileData,
FINDEX_SEARCH_OPS fSearchOp,
IntPtr lpSearchFilter,
int dwAdditionalFlags);
VB.NET Signature:
<DllImport("kernel32.dll", CharSet:=CharSet.Auto)> _
Private Function FindFirstFileEx(ByVal lpFileName As String, ByVal fInfoLevelId As FINDEX_INFO_LEVELS, ByRef lpFindFileData As WIN32_FIND_DATA, ByVal fSearchOp As FINDEX_SEARCH_OPS, lpSearchFilter As Int32, dwAdditionalFlags As Integer) As Int32
End Function
<DllImport("kernel32.dll", CharSet:=CharSet.Unicode)> _
Public Shared Function FindFirstFileExW(ByVal lpFileName As String, ByVal fInfoLevelId As FINDEX_INFO_LEVELS, ByRef lpFindFileData As WIN32_FIND_DATAW, ByVal fSearchOp As FINDEX_SEARCH_OPS, lpSearchFilter As IntPtr, dwAdditionalFlags As Integer) As IntPtr
End Function
Those 'int32's are IntPtr - and using an Int32 instead will fail on a 64-bit platform.
IntPtr hFile = FindFirstFileEx(
pattern,
findInfoLevel,
out findData,
FINDEX_SEARCH_OPS.FindExSearchNameMatch,
IntPtr.Zero,
additionalFlags);
int error = Marshal.GetLastWin32Error();
if (hFile.ToInt32() != -1)
{
do
{
if ((findData.dwFileAttributes & FileAttributes.Directory) != FileAttributes.Directory)
{
Console.WriteLine("Found file {0}", findData.cFileName);
}
}
while (FindNextFile(hFile, out findData));
FindClose(hFile);
}
Alternative Managed API:
The FileInfo() class provides managed access to this information. As with all .NET file handling (as of framework 4) it is constrained in terms of the length of filename allowed.
The FindFirstFileEx API
11/23/2014 3:32:21 PM - -66.194.114.222
An IntPtr is a pointer to a memory location (unmanaged) that adapts to the platform it is running on (64-bit, etc.) UNLIKE a standard int/Integer. You should always use this type for unmanaged calls that require it, even though an int will appear to work on your development machine.
1/13/2008 4:00:13 AM - Damon Carr-72.43.165.29
Defines values that are used with the FindFirstFileEx function to specify the information level of the returned data.
12/8/2019 11:57:18 AM - -71.90.183.45
Defines values that are used with the FindFirstFileEx function to specify the type of filtering to perform.
12/8/2019 11:55:21 AM - -71.90.183.45
Contains information about the file that is found by the FindFirstFile, FindFirstFileEx, or FindNextFile function.
11/10/2021 10:35:50 AM - -62.91.108.152
Please edit this page!
Do you have...
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).