lundi 14 août 2017

Vector Manipulation with

I would like to use MFC with a combination of std::remove/remove_if with std:erase to manipulate a vector of > containing a list of file names from a recursively searched root. Imagine the following:

A dialog box containing: - two radio buttons (Keep and Delete) - a number of check boxes with file extensions as labels (TXT, DOC, XLS, CPP, etc) - a button to do the action

If I select Keep, I want to keep all the files with the checked extensions or delete them if I select Delete. As an example, I thought I could use something similar to

void CFilesDlg::FilterFiles(void) { auto end = std::remove_if(g_vFiles.begin(), g_vFiles.end(), [&](std::shared_ptr const &strFile) { return ext == "TXT || ext == "DOC" });

g_vFiles.erase(end, g_vFiles.end());

}

if I wanted to keep or delete files with just those 2 extensions. But I'll never know which checkboxes are selected, so I'm not sure how to build my condition and I think if I try to use remove_if for one at a time, then files I want to keep or delete in addition to the first one will already be removed from the vector! I don't think remove can be used because it wants a specific value and obviously all the files and paths will be unique. I probably could iterate through the vector and keep or delete each one that meets my condition at that index, but that seems like overkill. So how do I go about accomplishing this?

I hope this makes sense and if something similar has been covered elsewhere, please direct me there. It also seems that in the preview of my question that the text I selected to be Code didn't format properly so I hope this doesn't complicate things. TIA

Aucun commentaire:

Enregistrer un commentaire