C语言-判断文件是否存在

 1 #include <stdbool.h>
 2 #include <sys/types.h>
 3 #include <sys/stat.h>
 4 #include <unistd.h>
 5 
 6 bool file_exist(const char *path)   // 返回值:0 - 不存在, 1 - 存在
 7 {
 8     struct stat st; 
 9 
10     return (stat(path, &st) == 0) && (!S_ISDIR(st.st_mode));
11 }

 

posted @ 2021-02-02 10:18  insistYuan  阅读(444)  评论(0编辑  收藏  举报