Searches a directory for a file whose name matches the specified file name (wildcards are allowed). One can use this function in combination with FindNextFile and FindClose to find all the files in the specified directory.
HANDLE FindFirstFile( LPCSTR lpFileName, WIN32_FIND_DATAA * lpFindFileData )
If the function succeeds, the return value is a search handle used in a subsequent call to FindNextFile or FindClose.
If the function fails, the return value is INVALID_HANDLE_VALUE.
EX1
int FindFirstFile_ex1() { // case1: List all file under c: string strPath = "c:\\*.*"; FindFirstFile_dir(strPath); return 1; } // a DOS dir command // can type into ScriptWindow "dir c:\*.*", for example. // void FindFirstFile_dir(string strFile) { WIN32_FIND_DATAA find; HANDLE hFile; //out_str(strFile); int nCount = 0; if((hFile=FindFirstFile(strFile,&find)) != INVALID_HANDLE_VALUE) { out_str(find.cFileName); nCount++; while(FindNextFile(hFile,&find)) { out_str(find.cFileName); nCount++; } printf("%d files found\n",nCount); FindClose(hFile); // must close the handle } else printf("%s: file(s) not found\n",strFile); }
FindNextFile, FindClose
origin.h