www.delorie.com/djgpp/doc/libc-2.01/libc_273.html   search  
Go to the first, previous, next, last section, table of contents.


findfirst

Syntax

#include <dir.h>

int findfirst(const char *pathname, struct ffblk *ffblk, int attrib);

Description

This function and the related findnext (see section findnext) are used to scan directories for the list of files therein. The pathname is a wildcard that specifies the directory and files to search for (such as subdir/*.c), ffblk is a structure to hold the results and state of the search, and attrib is a combination of the following:

FA_RDONLY
Include read-only files in the search
FA_HIDDEN
Include hidden files in the search
FA_SYSTEM
Include system files in the search
FA_LABEL
Include the volume label in the search
FA_DIREC
Include subdirectories in the search
FA_ARCH
Include modified files in the search

Any file that doesn't have any flag bits that aren't specified is selected for the search. Thus, if you specified FA_DIREC and FA_LABEL, you would get all subdirectories, the volume label, and any file that is neither read-only or modified.

The results of the search are stored in ffblk:

struct ffblk {
  char ff_reserved[21];     /* used to hold the state of the search */
  unsigned char ff_attrib;  /* actual attributes of the file found */
  unsigned short ff_ftime;  /* hours:5, minutes:6, (seconds/2):5 */
  unsigned short ff_fdate;  /* (year-1980):7, month:4, day:5 */
  unsigned long ff_fsize;   /* size of file */
  char ff_name[16];         /* name of file as ASCIIZ string */
}

Return Value

Zero if a match is found, nonzero if none found.

Example

struct ffblk f;
int done = findfirst("*.exe", &f, FA_ARCH|FA_RDONLY);
while (!done)
{
  printf("%10u %2u:%02u:%02u %2u/%02u/%4u %s\n",
    f.ff_fsize,
    (f.ff_ftime >> 11) & 0x1f,
    (f.ff_ftime >>  5) & 0x3f,
    (f.ff_ftime & 0x1f) * 2,
    (f.ff_fdate >>  5) & 0x0f,
    (f.ff_fdate & 0x1f),
    ((f.ff_fdate >> 9) & 0x7f) + 1980,
    f.ff_name);
  done = findnext(&f);
}


Go to the first, previous, next, last section, table of contents.

  prev next   webmaster     delorie software   privacy  
  Copyright © 1997     Updated Apr 1997