Here I report the code:
Code: Select all
wxDir directory(directoryName);
if (directory.IsOpened()) {
wxArrayString* exts = new wxArrayString();
exts->Add(".bmp");
exts->Add(".dib");
exts->Add(".jpeg");
exts->Add(".jpg");
exts->Add(".jpe");
exts->Add(".jp2");
exts->Add(".png");
exts->Add(".webp");
exts->Add(".pbm");
exts->Add(".pgm");
exts->Add(".ppm");
exts->Add(".sr");
exts->Add(".ras");
exts->Add(".tiff");
exts->Add(".tif");
this->files = new wxArrayString();
for (int i = 0; i < exts->GetCount(); i++ ) {
wxString filename;
bool res = directory.GetFirst(&filename);
if (res) {
do {
if (filename.EndsWith(exts->Item(i))) {
wxMessageBox(filename, "", wxOK);
files->Insert(filename, size);
size++;
}
res=directory.GetNext(&filename);
} while (res);
}
}
wxString str = wxString::Format("The first element is: %s The size of the array is: %d %d", files->Item(0), files->size(), size);
wxMessageBox(str, "", wxOK);
exts->Empty();
}
The first message box is working, so I know that portion of code is executed, but when the second message box is going to be created, the program throws an assertion failure due to index out of bound. I've tried using Add() instead of Insert, adding the "this->" when creating and using files, but nothing worked. The aim of this piece of code is enumerating the files into a given directory.
Can anyone help me or suggest me some other way to implement the code?
Thank You in advice.