The way I understand your question is this: you have a path, say, /foo/bar/baz
(baz is a file) and you want to know whether /foo/bar
exists. If so, the solution looks something like this (untested):
char *myDir = dirname(myPath);
struct stat myStat;
if ((stat(myDir, &myStat) == 0) && (((myStat.st_mode) & S_IFMT) == S_IFDIR)) {
// myDir exists and is a directory.
}