Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

C++ Program to Get The List of Files From Given Directory

Today, I am going to write a c++ Program which will print the list of files from the given Directory. I have used the opendir() function to open the given directory and readdir() function to read the directory.

readdir() function read the given directory and display the lists of all files inside that directory.

c++ program to get the list of files from given directory

Copy the below c++ program & change the directory path and then execute this program with the help of turbo c++ editor to get the list of files from the given directories.

#include
#include
#include
void main()
{
	struct dirent *ent;
	if ((dir = opendir ("c:\\src\\")) != NULL) {
	  /* print all the files and directories within directory */
	  while ((ent = readdir (dir)) != NULL) {
	    printf ("%s\n", ent->d_name);
	  }
	  closedir (dir);
	} else {
	  /* could not open directory */
	  perror ("");
	  return EXIT_FAILURE;
	}
}

The post C++ Program to Get The List of Files From Given Directory appeared first on FreeWebMentor.



This post first appeared on Programming Blog Focused On Web Technologies, please read the originial post: here

Share the post

C++ Program to Get The List of Files From Given Directory

×

Subscribe to Programming Blog Focused On Web Technologies

Get updates delivered right to your inbox!

Thank you for your subscription

×