Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Microsoft C 6.0 - <b>_dos_findfirst() find the first matching file</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 _dos_findfirst()        Find the first matching file

 #include   <dos.h>

  unsigned     _dos_findfirst(path, attributes, buffer);
  char *path;  File name and path
  unsigned attributes;   File attributes
  struct find_t *buffer; Location of returned information

    _dos_findfirst() uses MS-DOS function 4Eh to search for the first
    file that matches the name and attributes supplied. MS-DOS wildcards
    (? and *) may be used in the search.

    The attributes argument can be any of the following constants, either
    alone or OR'd together:

                    Constant     Meaning
                    ------------------------------------------------
                    _A_NORMAL    Normal file, can be read and written to.
                    _A_RDONLY    Read only file
                    _A_HIDDEN    Hidden file
                    _A_SYSTEM    System file
                    _A_VOLID     Volume ID
                    _A_SUBDIR    Subdirectory
                    _A_ARCH      Archive, file changed since last backup

    If a matching file is found the information about that file is
    returned in struct find_t, declared in dos.h, having the following
    members:

               struct find_t {
                   char reserved[21];   Reserved for use by MS-DOS
                   char attrib;         File attribute byte
                   unsigned wr_time;    Time file last modified
                   unsigned wr_date;    Date file last modified
                   long size;           Length of file in bytes
                   char name[13];       Null terminated name and extension
                   };                   of file

    Returns:    If _dos_findfirst() finds a matching file it returns 0,
                otherwise it returns the MS-DOS error code and sets errno
                to ENOENT. Normal attribute files are also returned when
                the specified attribute is _A_RDONLY, _A_HIDDEN,
                _A_SYSTEM, or _A_SUBDIR, even though none of these
                attributes are set.

      Notes:    If a matching file is found, the name and extension
                returned in find_t.name can be used to open the file.

                If you intend to use _dos_findnext() to find some
                additional matching files, do not change any information
                in find_t, since it is used to continue the search.

                In MS-DOS 3.0 or higher, dosexterr() can be used for
                extended error code information.

 Portability:   MS-DOS only, version 2.0 or higher

------------------------------- Example ---------------------------------

 This program finds the first file whose name starts with "r" in the default
 directory, whether hidden or normal.

           #include <dos.h>

           main()
           {
              struct find_t file_info;
              unsigned notfound;

              notfound = _dos_findfirst( "r*.*", _A_HIDDEN | _A_NORMAL,
           &file_info);
              if (notfound)
                 printf("No files match %s\n", "r*.*");
              else
                 printf("The name of the first matching file is %s\n",
           file_info.name);
           }


See Also: _dos_findnext()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson