Sunday, 13 March 2016

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

Problem:- C++ Program to List and Display Files in Current Directory or C Program to List Files in Directory or C Program to list all files and sub-directories in a directory or c program to list all files in a directory or C Program to List Files in Directory or Get Names of all Files in a Directory Program or C program to list files in directory or C Program to List and Display Files in Directory or C Program To List All Contents of Directory and Sub Directory or Listing Files and Directories sample program in C or C program to list all files in a directory recursively or List files in a directory (without folders) - C Board or How to Print a List of Files in a Windows Directory or c++ program to list all files in a directory.

Check This- Hacker rank Solution for C++ Sub Domain Introduction, Classes, STL, Inheritance.

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.

Also check- Geeksforgeeks solution for School, Basic, Easy, Medium, Hard Domain.

Extreme Recommended:- Like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date for a new post or if you have any Query you can ask there with lots of coders also suggest to your Friends to join and like our page, so we can help our community, and don't forget to Subscribe. Enter your Email and click to subscribe.


Tip:- Before copy the solution I recommended please read this full article, this will help you to build your own logic. If you have any query feel free to share with me, and if you like my work please share, comments and subscribe for our new and latest post related to programming this will help you update all about new post this Article.

Solution:-

#include<iostream>
#include<conio.h>
#include<dirent.h>
using namespace std;
main()
{
//Ghanendra Yadav
 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:-

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


You May Like This

1. C Program For Open A File (Or Open The Same Program Itself ) Itself Using File Handling

2. C++ Program To Merge Two File Into Third File Using File Handling

3. C++ Program For Copy One File To Another Using File Handling

4. C++ Program For Count A Character In File Using File

5. C++ Program For Reading A Number From File And Sum Of No. Line By Line Using File

6. Hacker Rank Solution for 30 Days of Code

7. Hacker Rank solution for Attribute Parser

8. Java Program For Find The Gross Salary Of An Employee

9. C++ Program For School Management System ( SMS Project ) With Source Code

10. Hacker Rank Solution For Mini-Max Sum


Extreme Recommended:- Like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date. If you have any Query or Question you can ask in the group, I will Try To Solve your Query and try to answers of your Questions withing 24 Hours, You can also Email me or comment below Please suggest to your Friends to join and like our page and don't forget to Subscribe. Enter your Email and click to subscribe.

Ghanendra Yadav

Ghanendra Yadav

Hello, I Am Ghanendra Yadav Owner of This Blog, I am professional Blogger and Programmer. I Love Programming, Logo Making, And Banner Designing. My Highest Qualification is MCA From NIT Warangal. You Can Find Me On Social Media Through Below Link And If You Have Any Query Related To Programming And Other Subject Comment Below or You Can Mail Me I Will Try To Answer Within 24 Hours Email:- yghanendra@student.nitw.ac.in

Find me on Social Media

Facebook | Twitter | Google+ | RSS Feed

No comments:

Post a Comment