I\'ve seen a few methods for checking the existence of a file in C. However, everything I\'ve seen works for a specific file name. I would like to check for any file that
You can use glob(3) (standardized by POSIX). You give it a wildcard pattern and it will search the filesystem for matches.
Example:
#include
#include
int main(int argc, char **argv)
{
glob_t globbuf;
if (0==glob(argv[1], 0, NULL, &globbuf)){
char **a=globbuf.gl_pathv;
puts("MATCHES");
for(;*a;a++)
puts(*a);
}
globfree(&globbuf);
}
Running:
./a.out 'lockfile*'
should give you your lockfiles.