A Program to print the names of the files in present directory. If you want to print the names of the files of some other directory (if the current user has sufficient permission), you may write the name of the directory in opendir() function.
#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>
int main (void)
{
DIR *dp;
struct dirent *ep;
dp = opendir ("./");
if (dp != NULL)
{
while (ep = readdir (dp))
puts (ep->d_name);
(void) closedir (dp);
}
else
perror ("Couldn't open the directory");
return 0;
}
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.