Answers for "how to check if a file is in a directory in c"

C
11

c check if file exists

if( access( fname, F_OK ) == 0 ) {
    // file exists
} else {
    // file doesn't exist
}
Posted by: Guest on January-06-2021
1

c check dir/file

#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);
}
Posted by: Guest on October-27-2020

Code answers related to "how to check if a file is in a directory in c"

Code answers related to "C"

Browse Popular Code Answers by Language