The best way is probably trying to open it, using just opendir() for instance.
Note that it's always best to try to use a filesystem resource, and handling any errors occuring because it doesn't exist, rather than just checking and then later trying. There is an obvious race condition in the latter approach.
You may also use access in combination with opendir to determine if the directory exists, and, if the name exists, but is not a directory. For example:
#include <sys/stat.h>
#include <dirent.h>
#include <unistd.h>
/* test that dir exists (1 success, -1 does not exist, -2 not dir) */
int
xis_dir (const char *d)
{
DIR *dirptr;
if (access ( d, F_OK ) != -1 ) {
// file exists
if ((dirptr = opendir (d)) != NULL) {
closedir (dirptr); /* d exists and is a directory */
} else {
return -2; /* d exists but is not a directory */
}
} else {
return -1; /* d does not exist */
}
return 1;
}