Originally Posted by
twomers
Hmmm ... it doesn't seem to recognise dir.h ...
any ideas???
I wrote you a quick example, under windows you have to use FindFirstFile and FindNextFile, but like all windows API functions it is hardly intuitive also I don't see why they couldn't just make it one function.
Code:
#include <stdio.h>
#include <windows.h>
/*
* listfiles.c, an example of listing files
* in a directory using Windows API.
*/
int main(void)
{
WIN32_FIND_DATA ffd;
char dir[] = "c:\\program files\\*"; /* '*' is a wildcard character
it tells FindFirstFile to
find any file in the directory */
HANDLE h = FindFirstFile(dir, &ffd);
if (h == INVALID_HANDLE_VALUE) {
printf("Unable to list files.");
return 0;
}
printf("Listing files in directory %s\n", dir);
do {
printf("%s\n", ffd.cFileName); /* ffd.cFileName is the name of the
file found */
} while (FindNextFile(h, &ffd) != 0);
return 0;
}