You can call the stat() function and use the S_ISREG() macro on the st_mode field of the stat structure in order to determine if your path points to a regular file:
xxxxxxxxxx
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
int is_regular_file(const char *path)
{
struct stat path_stat;
stat(path, &path_stat);
return S_ISREG(path_stat.st_mode);
}
Note that there are other file types besides regular and directory, like devices, pipes, symbolic links, sockets, etc. You might want to take those into account.
from : Frédéric Hamidi (https://stackoverflow.com/questions/4553012/checking-if-a-file-is-a-directory-or-just-a-file)
xxxxxxxxxx
int isValidFile(char* path)
{
FILE* checker = fopen(path, "r");
if (checker)
{
fclose(checker);
return 1;
}
else
{
return 0;
}
}