I have the following code in Linux that looks for files that matches the given wildcard:
std::vector<std::string> listFilenamesInPath(std::string wildcard = "*", std::string directory = "./")
{
std::vector<std::string> result;
DIR* dirp = opendir(directory.c_str());
if (dirp)
{
while (true)
{
struct dirent* de = readdir(dirp);
if (de == NULL)
break;
if (fnmatch(wildcard.c_str(), de->d_name, 0))
continue;
else
result.push_back (std::string(de->d_name));
}
closedir(dirp);
}
std::sort(result.begin(), result.end());
return result;
}
I´m porting this code to Windows and found out that fnmatch
is not available (dirent
is also not available, but I could find one according to the following SO link.
Is there a fnmatch substitute function that does exactly the same thing ?
How can I make this code compile and run in a VS2012 without breaking up my logic ?