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 Library Reference - <u>synopsis:</u> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Synopsis:
    #include <direct.h>
    struct dirent *opendir( const char *dirname );
    struct _wdirent *_wopendir( const wchar_t *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.

    #if defined(__OS2__) || defined(__NT__)
    #define NAME_MAX 255    /* maximum for HPFS or NTFS */
    #else
    #define NAME_MAX  12    /* 8 chars + '.' +  3 chars */
    #endif

    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[ NAME_MAX + 1 ]; /* file's name */
        unsigned short 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.

    The _wopendir function is identical to opendir except that it accepts a
    wide-character string argument and returns a pointer to a  _wdirent
    structure that can be used with the  _wreaddir and  _wclosedir
    functions.

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

    struct _wdirent {
        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 */
        wchar_t d_name[NAME_MAX+1];/* file's name */
        unsigned short d_ino;   /* serial number (not used) */
        char    d_first;        /* flag for 1st time */
    };

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.

    Constant     Meaning

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

ENOENT
    The named directory does not exist.


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:
    opendir is POSIX 1003.1, _wopendir is not POSIX

Systems:
     opendir - All, Netware

    _wopendir - DOS, Windows, Win386, Win32, OS/2 1.x(all), OS/2-32

See Also:
    closedir, _dos_find Functions, readdir, rewinddir

See Also:

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