C Language Development Kit/Functions/FindFirst

From OptiWiki

Jump to: navigation, search
Description Searches through the filesystem, and returns the name of the first file that matches filename, which may include wildcards.
Syntax
int findfirst(char *filename, struct ffblk *ffblk);
Arguments
char *filename
Points to a string containing the file where findfirst() is looking for. This filename may contain the wildcards ? (matches one character) and * (matches a series of characters up to the end of a filename, or extension).
struct ffblk *ffblk
*ffblk is a pointer to a ffblk structure that is used to return the search result. The structure is defined as follows:
struct ffblk
{
	char name[D_NAME+1];         // The name of the file that was found
	char ext[D_EXT+1];           // The extension of the file that was found
	long filesize;               // The size of the file that was found
	char search_name[D_NAME+1];  // Internally used by the findnext() function
	char search_ext[D_EXT+1];    // Internally used by the findnext() function
	int slot;                    // Internally used by the findnext() function
// Since the OPH100x can have more then one drive, it has one extra member:
#ifdef OPH
	int drive;                    // Internally used by the findnext() function
#endif
};
Returns
0 Success in finding *filename.
-1 No success in finding *filename.
Remarks Unless explicitly specified by the file name, the default drive will be searched. Use the function set_default_drive to select that drive.
Example
#include <stdio.h>
#include <stdlib.h>
#include "lib.h"
 
void main( void )
{
    struct ffblk  ffblk;
    int done;
 
    for(;;)
    {
        printf("\fDirectory  *.*\n");
        done = findfirst( "*.*",);
        while( !done )
        {
            printf("  %s.%s\n", ffblk.name, ffblk.ext);
            done = findnext(  );
            while( getchar() == EOF )
                idle();
        }
        printf("listing ready!");
        while( getchar() == EOF )
            idle();
    }
}


Views
Personal tools