Q:

C++ Program to List and Display Files in Current Directory / Folder Using File Handling

0

Explanation:-

 So in this problem, we have to print the all directory/folder and subdirectory and subfolder. We have to print only the name of all directory/folder and subdirectory and subfolder. using file handling in which our program is situated or our program is saved in the directory.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include<iostream>
#include<conio.h>
#include<dirent.h>
using namespace std;
main()
{
 int done, i=1;
 DIR *dir;
 dirent *pdir;
 cout<<"Press any key to list and view all the files in the current directory : \n";
 getch();
 dir=opendir(".");
 while(pdir=readdir(dir))
 {
 cout<<i<<"="<<pdir->d_name<<" \n";
 i++;
 }
 closedir(dir);
 return 0;
}

 

Output:

Press any key to list and view all the files in the current directory : 

1=main.cpp 

2=.. 

3=. 

4=a.out 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Program to Copy Contents of One File to Another in... >>
<< C++ Program To Count Number Of Characters In a Fil...