Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Watcom C/C++ v10.0 : C library - <b>synopsis:</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Synopsis:
    #include <direct.h>
    struct dirent *readdir( DIR *dirp );

Description:
    The readdir function obtains information about the next matching file
    name from the argument dirp.  The argument dirp is the value returned
    from the  opendir function.  The readdir function can be called
    repeatedly to obtain the list of file names contained in the directory
    specified by the pathname given to  opendir.  The function  closedir
    must be called to close the directory and free the memory allocated by
     opendir.

    The file <direct.h> contains definitions for the structure  dirent.

    typedef struct dirent {
        char    d_dta[ 21 ];       /* disk transfer area */
        char    d_attr;            /* file's attribute */
        unsigned short int d_time; /* file's time */
        unsigned short int d_date; /* file's date */
        long    d_size;            /* file's size */
        char    d_name[ 13 ];      /* file's name */
        ino_t   d_ino;             /* serial number */
        char    d_first;           /* flag for 1st time */
    } DIR;

Returns:
    When successful, readdir returns a pointer to an object of type struct
    dirent.  When an error occurs, readdir returns the value NULL and  errno
    is set to indicate the error.  When the end of the directory is
    encountered, readdir returns the value NULL and  errno is unchanged.

Errors:
    When an error has occurred,  errno contains a value indicating the type
    of error that has been detected.

    EBADF
        The argument dirp does not refer to an open directory stream.


See Also:
    closedir, _dos_find Functions Functions, opendir

Example:
    To get a list of files contained in the directory \watcom\h on your
    default disk:

    #include <stdio.h>
    #include <direct.h>

    void main()
      {
        DIR *dirp;
        struct dirent *direntp;

        dirp = opendir( "\\watcom\\h" );
        if( dirp != NULL ) {
          for(;;) {
            direntp = readdir( dirp );
            if( direntp == NULL ) break;
            printf( "%s\n", direntp->d_name );
          }
          closedir( dirp );
        }
      }

    Note the use of two adjacent backslash characters (\) within
    character-string constants to signify a single backslash.

Classification:
    POSIX 1003.1

Systems:
    All

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