Currently I am working on a module that reads a directory looking for files with specific pattern in filenames. I am using boost::filesystem. I've been thinking that it would be good idea to have something that mimics filesystem without directly interacting with it, unless it's production code.
I found this link: http://ift.tt/1RxfiEI Looked great, but when I tried to use this code. I found that calling next() could throw if there's no more files. I'm not sure if code like this is considered a good practice:
std::vector<std::string> results;
try
{
std::string s = directory_scanner.next;
if (s.find("some_pattern")
results.push_back(s);
}
catch(...){hmm now what?}
This looked like a generic solution, so I was interested with this. But maybe it's completely wrong now in 2016 :)
Maybe it's better to have a virtual method 'get_interesting_files' in directory scanner and inject it to an object that needs to be unit tested?
Aucun commentaire:
Enregistrer un commentaire