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......

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).

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. :)

Edited 6 Years Ago by nbaztec: n/a

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.

Edited 6 Years Ago by nbaztec: n/a

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.

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?

This question has already been answered. Start a new discussion instead.