Below is not a elegant code but i was trying to get a hang of wxWidgets..
I tried using BeforeLast to get the Dir name but not sure how to make it a generic code ,i.e., make it work with all kinds of file name..
But then i am not sure how to get the file name alone..
Ok the aim is that i will get a input as a file but i need to separate the file name and dir name..
Code: Select all
void Test2Frame::OnOpen(wxCommandEvent& WXUNUSED(event))
wxString file, fileDir, tempName;
wxFileDialog* openFileDialog = new wxFileDialog(this, _("Open XML file"), "", "","XML files| *.xml", wxFD_OPEN|wxFD_FILE_MUST_EXIST);
if (openFileDialog->ShowModal() == wxID_CANCEL)
file = openFileDialog->GetPath();
wxLogMessage("File output %s", file);
wxLogError("Cannot open file '%s'.", file);
struct stat fileStat; stat(file, &fileStat);
wxCharBuffer filepath = file.ToUTF8();
//do something with the file..
size_t pathLen = file.Len();
wxLogMessage("File length %d", pathLen);
wxLogMessage("BeforeLast %s", file.BeforeLast('a'));// get the Dir name but the file name needs to start with "a"