FindFirstFileEx (kernel32)
Last changed: -66.194.114.222

.
Summary

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);

User-Defined Types:

FINDEX_INFO_LEVELS

FINDEX_SEARCH_OPS

WIN32_FIND_DATA

// dwAdditionalFlags:
public const int FIND_FIRST_EX_CASE_SENSITIVE= 1;
public const int FIND_FIRST_EX_LARGE_FETCH = 2;

Notes:

None.

Tips & Tricks:

Please add some!

Sample Code:

    WIN32_FIND_DATA findData;
    FINDEX_INFO_LEVELS findInfoLevel = FINDEX_INFO_LEVELS.FindExInfoStandard;
    int additionalFlags = 0;
    if (Environment.OSVersion.Version.Major >= 6)
    {
    findInfoLevel = FINDEX_INFO_LEVELS.FindExInfoBasic;
    additionalFlags = FIND_FIRST_EX_LARGE_FETCH;
    }

    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.

Documentation