RAD Studio |  |

rewinddir, wrewinddir

Header File

dirent.h

Category

Directory Control Routines

Prototype

void rewinddir(DIR *dirp);

void wrewinddir(wDIR *dirp);

Description

Resets a directory stream to the first entry.

rewinddir is available on POSIX-compliant UNIX systems.

The rewinddir function repositions the directory stream dirp at the first entry in the directory. It also ensures that the directory stream accurately reflects any directory entries that might have been created or deleted since the last opendir or rewinddir on that directory stream.

wrewinddir is the Unicode version of rewinddir.

Return Value

None.

Example

Copy Code

    /* opendir.c - test opendir(), readdir(), closedir() */

    #include <dirent.h>
    #include <stdio.h>
    #include <stdlib.h>

    void scandir(char *dirname)
    {
       DIR *dir;
       struct dirent *ent;

       printf("First pass on '%s':\n",dirname);
       if ((dir = opendir(dirname)) == NULL)
       {
         perror("Unable to open directory");
         exit(1);
       }
       while ((ent = readdir(dir)) != NULL)
         printf("%s\n",ent->d_name);

       printf("Second pass on '%s':\n",dirname);
       rewinddir(dir);
       while ((ent = readdir(dir)) != NULL)
         printf("%s\n",ent->d_name);
       if (closedir(dir) != 0)
         perror("Unable to close directory");
     }

     void main(int argc,char *argv[])
     {
       if (argc != 2)
       {
         printf("usage: opendir dirname\n");
         exit(1);
       }
       scandir(argv[1]);
       exit(0);
    }

Portability

| POSIX | Win32 | ANSI C | ANSI C++
rewind | + | + |  |
wrewinddir |  | + |  |

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!