I want to make a c++ program which scan all drives and generate list of all files and folder.
how can i do it in c++?
Plz help me......

Recommended Answers

All 13 Replies

What have you tried so far?

Int main()
{
char buff[bufsiz],ch;
file *ptr,*fp1;
fp1=fopen("c:\\prc.txt","a+");
if(ptr=popen("dir /b /-s","r")!=null)
while(fgets(buff,bufsiz,ptr)!=null)
fprintf(fp1,buff);
pclose(ptr);
fclose(fp1);
}


i did it. Using this i am able to generate list of all files and folders of a drive in text file.
But i have two problems
1. I have to changedirectry myself. It does not get drive names itself and generate list.

2. This program is based on command prompt(dir command).

Use recursion.

Be warned that scanning a drive for all files and directories will take a while, depending on how much stuff you have on there.

>>Be warned that scanning a drive for all files and directories will take a while, depending on how much stuff you have on there.
On my 500GB SATA-HDD/7200rpm it took a whooping 30mins(I caught up with a sitcom meanwhile). Then I made it multi-threaded, could barely catch 5 minutes of the show. :)

5 minutes still isn't exactly instant though ;)

Also, if the op wants to do this properly then the op should probably not use the DIR system command, but switch to using the FindFirstFile function :)

>>5 minutes still isn't exactly instant though
I have a bulky C drive, only 1GB ram. C'mon give the poor threads some credit. :P

>>op should probably not use the DIR system command, but switch to using the FindFirstFile function
system()/shell calls, will take centuries if not ages to scan a 500GB HDD, I on the other hand used the FindFirstFile.

Can you provide me some code using findfirst and findnext function.
i know ,i have to use recursion but how i can?
I am not getting it.

Let me give you a hint: You have to recurse until no directories are found. Good Luck.

I know it but how can i write code for it.
It is my confusion.

I know it.
The problem is how can i do it in c.
So can you provide me some code for it?

Thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.