I'm thinking that what Salem said should be your clue.
Note that you are looking in 'path' (which is a global??), but then you are not prepending path to the file names that you are looking at, so most likely the stat is failing, and you are calling S_ISDIR() on memory garbage, which may or may not have that bit set, but which *will* be the same for all files.
I'd suspect that if you initialized the stat struct to 0 ( memset(&statbuf, 0, sizeof(statbuf)); ) that you would find no files pushed to your vector (which is also global??)
so yeah ... all that is to say
1) call stat with the path prepended:
2) check the return of stat to make sure you're doing it right:
snprintf(fullpath, 1024, "%s/%s", path.c_str(), ep->d_name);
if (stat(fullpath, &statbuf) == 0)
// do stuff
printf("Huh, can't find and stat %s\n", fullpath);