FindFirstFile function
The FindFirstFile function searches a directory for a file or subdirectory that matches a specified name pattern.
Syntax
WINAPI HANDLE FindFirstFileW(
LPCWSTR lpFileName,
LPWIN32_FIND_DATAW lpFindFileData
);
Parameters
| Parameter | Type | Description |
|---|---|---|
| lpFileName | LPCWSTR | Pointer to a null-terminated string that specifies the directory or path, and the file name pattern. Wildcards * and ? are permitted. |
| lpFindFileData | LPWIN32_FIND_DATAW | Pointer to a WIN32_FIND_DATA structure that receives information about the found file or subdirectory. |
Return value
If the function succeeds, the return value is a search handle that can be used in subsequent calls to FindNextFile and FindClose. If the function fails, the return value is INVALID_HANDLE_VALUE. Use GetLastError to obtain extended error information.
Example (C++)
#include <windows.h>
#include <iostream>
int main() {
WIN32_FIND_DATAW findFileData;
HANDLE hFind = FindFirstFileW(L"C:\\\\Windows\\\\System32\\\\*.dll", &findFileData);
if (hFind == INVALID_HANDLE_VALUE) {
std::wcout << L"No files found or error." << std::endl;
return 1;
}
do {
std::wcout << findFileData.cFileName << std::endl;
} while (FindNextFileW(hFind, &findFileData));
FindClose(hFind);
return 0;
}