C Program that prints the names of the files in the current working directory - BunksAllowed

BunksAllowed is an effort to facilitate Self Learning process through the provision of quality tutorials.

Community

C Program that prints the names of the files in the current working directory

Share This

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; }




Happy Exploring!

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.