1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| int ListSubFiles(char const * path, char const * filter)
{
int rc = -1;
if (path && filter)
{
HANDLE hFile = NULL;
WIN32_FIND_DATA ffInfo = { 0 };
char LocPath[MAX_PATH] = { '\0' };
size_t lgPath = strlen(path);
size_t lgFilter = strlen(filter);
if ( (lgPath + lgFilter + 1) >= MAX_PATH ) {
return rc;
}
strcpy(LocPath, path);
strcat(LocPath, "\\");
strcat(LocPath, filter);
hFile = FindFirstFile(LocPath, &ffInfo);
if (hFile) {
if (ffInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
printf("DIRECTORY: %s\n", ffInfo.cFileName);
}
else {
puts(ffInfo.cFileName);
}
while (FindNextFile(hFile, &ffInfo)) {
if (ffInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
printf("DIRECTORY: %s\n", ffInfo.cFileName);
}
else {
puts(ffInfo.cFileName);
}
}
FindClose(hFile); hFile = NULL;
rc = 0;
}
}
return rc;
}
[...]
ListSubFiles("C:\\Program Files", "*"); |
Partager