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.

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

Popular posts from this blog

CSL 204 OPERATING SYSTEM LAB KTU IV SEM CSE

FCFS and SJF

Shared Memory Inter-Process Communication ( IPC)