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:
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)