Reading Directory Contents
opendir(), readdir(), and closedir():
These functions are used for directory traversal.
opendir(): Opens a directory stream.
readdir(): Reads the next directory entry (file or subdirectory).
closedir(): Closes the directory stream.
opendir(): Opens a directory stream.
readdir(): Reads the next directory entry (file or subdirectory).
closedir(): Closes the directory stream.
Example:
#include <dirent.h>
#include <stdio.h>
int main()
{
DIR *dir = opendir(".");
if (dir) {
struct dirent *entry;
printf("Current Directory Contents\n");
while ((entry = readdir(dir)) != NULL)
{
printf("%s\n", entry->d_name);
}
closedir(dir); }
return 0;
}
Comments
Post a Comment