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>
    DIR *opendir( const char *dirname );

Description:
    The opendir function is used in conjunction with the functions  readdir
    and  closedir to obtain the list of file names contained in the
    directory specified by dirname.  The path indicated by dirname can be
    either relative to the current working directory or it can be an
    absolute path name.  As an extension to POSIX, the last part of dirname
    can contain the characters '?' and '*' for matching multiple files
    within a directory.

    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;
    More than one directory can be read at the same time using the  opendir,
     readdir, and  closedir functions.

Returns:
    The opendir function, if successful, returns a pointer to a structure
    required for subsequent calls to  readdir to retrieve the file names
    matching the pattern specified by dirname.  The opendir function returns
    NULL if dirname is not a valid pathname, or if there are no files
    matching dirname.

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

    EACCES
        Search permission is denied for a component of dirname or read
        permission is denied for dirname.

    ENOENT
        The named directory does not exist.


See Also:
    closedir, _dos_find Functions Functions, readdir

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 ) {
          perror( "" );
        } else {
          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