regexec for filtering files in a directory
"Keith Bottner" <[email protected]>
| Newsgroups | gmane.os.freebsd.newbies |
|---|---|
| Organization | Barking Lizards Technologies |
| Message-ID | <[email protected]> |
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(®, "^.+\\.c$", REG_EXTENDED | REG_NOSUB);
DIR * dirp = opendir("~/");
struct dirent * pDirEnt;
while ((pDirEnt = readdir(dirp)) != NULL)
{
err = regexec(®, 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
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-newbies
To unsubscribe, send any mail to "[email protected]"