標準/拡張機能 | C/C++ | 依存項目 |
---|---|---|
POSIX.1 |
両方 |
#define_POSIX_SOURCE
#include <dirent.h>
void rewinddir(DIR *dir);
オープン・ディレクトリー・ストリームを先頭へと位置変更します。dir は、オープン・ディレクトリーと関連した DIR オブジェクト を指しています。
readdir() への次の呼び出しで、ディレクトリーの最初のエントリーが読み取 られます。ディレクトリーのオープン以後に、ディレクトリーの内容が変更されていた場合 には、rewinddir() への呼び出しで、ディレクトリー・ストリームが更新されるので、以降の readdir() で、新しい内容を読み取ることができます。
rewinddir() は、値を戻しません。
⁄* CELEBR15
This example produces the contents of a directory by opening it,
rewinding it, and closing it.
*⁄
#define _POSIX_SOURCE
#include <dirent.h>
#include <errno.h>
#include <sys⁄types.h>
#undef _POSIX_SOURCE
#include <stdio.h>
main() {
DIR *dir;
struct dirent *entry;
if ((dir = opendir("⁄")) == NULL)
perror("opendir() error");
else {
puts("contents of root:");
while ((entry = readdir(dir)) != NULL)
printf("%s ", entry->d_name);
rewinddir(dir);
puts("");
while ((entry = readdir(dir)) != NULL)
printf("%s ", entry->d_name);
closedir(dir);
puts("");
}
}
contents of root:
. .. bin dev etc lib tmp u usr
. .. bin dev etc lib tmp u usr