Originally posted by Andrewthegreen
how would i get a list of files in directorys in any given directory?
use the findfirstfile and then findnextfile commands with a *.* paramater as the filename? or maybe the ex ones?
You can use the FindFirstFile & FindNextFile Apis....
Code:
#include <windows.h>//For FindFirstFile etc
#include <iostream>//For cout etc
#include <string>//For...well...ugh...string!
using std::string;
using std::cout;
using std::cin;
using std::endl;
int main(int argc,char** argv){
WIN32_FIND_DATA wfd;//This holds the data on a found file
string str;//To hold directory path
cout << "Enter Directory to list files for" << endl;
cin >> str;//Get path
str += "\\*.*";//Add this to indicate we want all files
HANDLE hFile = FindFirstFile(str.c_str(),&wfd);//Find first
if(hFile ==INVALID_HANDLE_VALUE){//If error..abort
cout << "Error!! Aborting" << endl;
return 1;
}
do{
cout << wfd.cFileName << endl;
}while(FindNextFile(hFile,&wfd));//Get the rest of the files
FindClose(hFile);//Clean up!
return 0;
}