What I do now is erase also the last two letters (/ or \\) then get the last / or \\. Works as I know the upper directory to contain at least two letters.
InFileCopyFrom.erase (InFileCopyFrom.end()-18, InFileCopyFrom.end());
string::size_type nn = InFileCopyFrom.find_last_of("/\\:");
if (nn == string::npos) XPLMDebugString("The plugin folder is missing.\n");
InFileCopyFrom = InFileCopyFrom.substr(0, nn + 1);