programming.nbk: Home | Index | Next Page: C io.h | Previous Page: C functions


 C functions for searching for files

defined in io.h:

    /*
     * Functions for searching for files. _findfirst returns -1 if no match
     * is found. Otherwise it returns a handle to be used in _findnext and
     * _findclose calls. _findnext also returns -1 if no match could be found,
     * and 0 if a match was found. Call _findclose when you are finished.
     */
    int	_findfirst (const char* szFilespec, struct _finddata_t* find);
    int	_findnext (int nHandle, struct _finddata_t* find);
    int	_findclose (int nHandle);

usage:

    struct _finddata_t c_file;
    long hFile;
    if ( (hFile = _findfirst("*.c", &c_file)) == -1L ) {
        printf("No *.c files in current directory");
    }
    else {
        do {
            printf("%s\n", c_file.name);
        } while ( _findnext(hFile, &c_file) == 0 )
        _findclose(hFile);
    }

the _finddata_t struct:

    /*
     * The following structure is filled in by _findfirst or _findnext when
     * they succeed in finding a match.
     */
    struct _finddata_t
    {
        	unsigned	attrib;		/* Attributes, see constants above. */
        	time_t		time_create;
        	time_t		time_access;	/* always midnight local time */
        	time_t		time_write;
        _fsize_t	size;
        char		   name[FILENAME_MAX];	/* may include spaces. */
    };

programming.nbk: Home | Index | Next Page: C io.h | Previous Page: C functions


Notebook exported on Monday, 7 July 2008, 18:56:06 PM Eastern Daylight Time