regexec for filtering files in a directory

Keith Bottner keith at barkinglizards.com
Fri Jan 21 13:20:22 PST 2005


I am trying to use the regcomp and regexec methods to filter files from a
directory; however, the regexec function always says that it matches the
pattern. Is there any problems with the regex functions? Or something in the
code that I am just missing? Or is there just a better way to do what I am
trying to do?
 
Basically:
 
regex_t reg;
 
int err = regcomp(&reg, "^.+\\.c$", REG_EXTENDED | REG_NOSUB);
 
DIR * dirp = opendir("~/");
 
struct dirent * pDirEnt;
while ((pDirEnt = readdir(dirp)) != NULL)
{
    err = regexec(&reg, pDirEnt->d_name, 0, 0, 0);
    if (err == 0)
    {
        printf("%s\n", pDirEnt->d_name);
    }
}
 
regfree(&preg);
 
closedir(dirp);
 
 
Thanks,
 
Keith
 

-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.7.1 - Release Date: 1/19/2005
 


More information about the freebsd-newbies mailing list