I have tried a lot of methods but all have failed so I need some help from wounderful smart people like you
I am trying to scan a single directory and return all the files in that directory.
Does anyone know how I can go about this?
Thanks.
I have tried a lot of methods but all have failed so I need some help from wounderful smart people like you
I am trying to scan a single directory and return all the files in that directory.
Does anyone know how I can go about this?
Thanks.
depends on the operating system but all of them involve some sort of recursion. For MS-Windows see FindFirstFile() and FindNextFile() win32 api functions. When a directory is encountered, make a recursive call and start all over again in the new directory.
You could just use the system function (which sends commands to the OS).
But instead of call it, cout it.
For a Windows based OS, the following will work:
Just search google for attributes to dir command, say for alphabetical order, by file size, ect. If that is what you are asking/trying to do?Code:#include <iostream> using namespace std; int main () { cout << system("dir"); system("PAUSE"); return 0; }
The code I posted will just display the directory of the exe. See google dir search for displaying it for any directory. Just remember to ‘escape’ the \ in c++ so it would be c:\\directory.
Last edited by Enahs; 11-03-2005 at 04:46 PM.
What I am trying to do is return each indvidual file in a directory. I cant use FindNextFile etc because to m knowledge they are only for Windows OS, I have a Linux OS. I do like the dir command but I cant see how it would return individual files.
Thanks
Check the FAQ: Level 3 - Accessing a directory and all the files within it.