Finding wildcards in readdir

I am having a hard time doing this and can't seem to find an example to help me. This is my code:

DIR *dirp=opendir(pathname);
struct stat filebuf;
struct dirent entry;
struct dirent dp=&entry;
RWCString pattern;
for (int i = 0; i < request_->getNumStreams(); i++)
{
stream = request_->getStream(i);
tpdfilter = vehicle + filter + stream + filter + tpd;
if (prefix == "")
pattern = "
" + tpdfilter;
else
pattern = prefix + filter + tpdfilter;
while(dp = readdir(dirp))
{
stat(dp->d_name, &filebuf);
if ((!(fnmatch(pattern, dp->d_name,0)) == 0) && (stat(dp->d_name, &filebuf) != 0) && (S_ISDIR(filebuf.st_mode) == 1))
{
tpdfiles.append(pathname + dp->d_name);
}
}
}
closedir(dirp);

I am trying to find files in the directory that could look like this if I do an ls:

ls *FTRIG.NORMAL.*tpd*

There are too many files in the directory to run an ls with the wildcards. The wildcards are unknown and are user supplied from a file that is read in.

The fnmatch does not filter out the files that don't match the wildcard. I do not get directories so the other parts of the if statement are working.

Can anyone help? I am on unix, sun sparc 5.8 is that helps at all. Thanks.

Allyson

use code tags please.

fnmatch returns zero when it finds a match. !fnmatch() == 0 does the exact opposite.
Consider testing for FNM_NOMATCH if you want to skip entries. You also should be checking for FNM_ERROR.

If glob() exists in this version of SUN's os it may be what you are looking for.