hey
i used findfirst and findnext function but they can access only a path which is given by us. i want to access all folders and file of a drive like a antivirus do, when it scans the drive....
do u know how can we do it using c language?

Please post up a little snippet of code trying to do what you want, and let's see what the problem is.

i simply want to print name of all files and folders of the drive using c language.

An easy way would be to execute the ls command in your program...

system() calls should ALWAYS be avoided at all cost.
P.S. "ls" is for Linux & "dir" is for Windows.

findfirst and findnext are the functions you're seeking. You may need to use recursion to search deeper into directories.

Why should system calls be avoided if you know your target environment ?

Why should system calls be avoided if you know your target environment ?

Because it is expensive. It is like taking a "Boeing 747" to go for groceries to the local supermarket.

commented: Nice way of putting it :) +1

i simply want to print name of all files and folders of the drive using c language.

Programming forums in general, have a problem with that type of request. "I simply want some code for this problem", type of requests, don't go over well, I'm afraid.

Show some effort on your part, and post your code relating to this problem. In the sticky posts, the forum makes it clear what type of posts should be given help, and what type should not.

Why should system calls be avoided if you know your target environment ?

Well for 1 they tend to make your application slower & inefficient. It's like using your furniture to produce heat, or calling a bull-dozer to open your front door.
The events taking place upon calling system() are roughly the foll:
1. Suspends your program.
2. Calls the OS Shell. (Slowest Step)
3. OS Shell finds the command.
4. Allocates memory to execute it.
5. Executes it.
6. Deallocates memory
7. Exits the shell.
8. Resumes your program.

For 2, take the following example under Windows Environment:

system("dir");

Suppose the end-user has an executable dir.exe in the current directory, so instead of executing the "dir" command on the shell, the program opens/executes "dir.exe", which under extreme conditions might even be a file-deleting virus!
Pretty much, if it's available as a shell command, it can be done in C++.

Well for 1 they tend to make your application slower & inefficient. It's like using your furniture to produce heat, or calling a bull-dozer to open your front door.
The events taking place upon calling system() are roughly the foll:
1. Suspends your program.
2. Calls the OS Shell. (Slowest Step)
3. OS Shell finds the command.
4. Allocates memory to execute it.
5. Executes it.
6. Deallocates memory
7. Exits the shell.
8. Resumes your program.

For 2, take the following example under Windows Environment:

system("dir");

Suppose the end-user has an executable dir.exe in the current directory, so instead of executing the "dir" command on the shell, the program opens/executes "dir.exe", which under extreme conditions might even be a file-deleting virus!
Pretty much, if it's available as a shell command, it can be done in C++.

When you do not mention the original source, it is called plagiarism if you make it to look like it came from you.
http://www.gidnetwork.com/b-61.html

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.