Hi,
I wrote this little function to grab files inside a folder. However, although it compiles fine, the program crashes on starting (Segmentation fault?):
Code:
#include <iostream>
#include <windows.h>
#include <fstream>
#include <vector>
using namespace std;
void grabFiles(char* root, vector<string> &endList); //Grabs files, and dumps them into vector.
void grabFiles(char* root, vector<string> &endList)
{
vector< WIN32_FIND_DATA > tmpFiles;
HANDLE h;
int i;
WIN32_FIND_DATA tmpFile;
// build a list of files
h = FindFirstFile("*.*", &tmpFile);
tmpFiles.push_back(tmpFile);
if (h != INVALID_HANDLE_VALUE)
{
do
{
if (!(strcmp(tmpFile.cFileName, ".") == 0 || strcmp(tmpFile.cFileName, "..") == 0))
{
tmpFiles.push_back(tmpFile);
}
} while (FindNextFile(h, &tmpFile));
if (GetLastError() != ERROR_NO_MORE_FILES) exit(-1);
FindClose(h);
}
for(int x=0; x < tmpFiles.size(); x++)
{
endList.push_back(tmpFiles[i].cFileName);
}
}
int main(int argc, char *argv[])
{
vector<string> theLists;
grabFiles(".", theLists);
for(int e=0; e<theLists.size(); e++)
{
cout<<theLists[e]<<"\n\n";
}
cin.get();
return(0);
}