This self-explanatory code section provides an example on how to use the file listing functions.
/****************************************************************************/
/* GetDirectFiles */
/****************************************************************************/
/* TASK: this function gets the number of archives in the given folder */
/* PARAMETERS: dirname -> the name of the directory */
/* RETURNS: -1 if the directory does not exist, the number of archives otherwise */
/* NOTES: none */
int GetDirectFiles (char dirname [])
{
char lname [MAX_PATHNAME_LEN];
char lname1 [MAX_PATHNAME_LEN];
int result = -1;
/* If the directory exists */
if (GetFirstFile (dirname, 0, 0, 0, 0, 0, 1, lname)
== 0)
{
result = 0;
strcpy (lname, dirname);
strcat (lname, "\\*.*");
/* Get the first file in the directory */
if (GetFirstFile (lname, 1, 0, 0, 0, 0, 0, lname1) == 0)
{
result++;
/* Get the next file in the directory */
while (GetNextFile (lname1) == 0)
result++;
}
}
return result;
}
You may enhance it by supplying the required file extension as a parameter (instead of *.*).
You should also create your own list of file names to store the results from GetFirstFile and GetNextFile.
Bye
Giovanni