Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 21 Jan 2005 15:18:21 -0600
From:      "Keith Bottner" <keith@barkinglizards.com>
To:        "Freebsd-Newbies@Freebsd. Org" <freebsd-newbies@freebsd.org>
Subject:   regexec for filtering files in a directory
Message-ID:  <20050121212021.EC93A43D2D@mx1.FreeBSD.org>

next in thread | raw e-mail | index | archive | help
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
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050121212021.EC93A43D2D>