[阅读: 574] 2005-10-26 03:46:59
#include "FindFiles.h"
int findFiles(char* pattern, FINDCALLBACK action)
{
int batchFileCount = 0;
HANDLE hFind;
// search for the files
WIN32_FIND_DATA findData;
hFind = FindFirstFile(pattern, &findData);
if ( hFind == INVALID_HANDLE_VALUE ) {
printf("not found for pattern %s", pattern);
} else {
// handle first file
action(&findData);
batchFileCount++;
// for-each file found
while ( FindNextFile(hFind, &findData) != 0 ) {
action(&findData);
batchFileCount++;
}
FindClose(hFind);
}
return batchFileCount;
}