linux c检查文件是否存在

来源:互联网 发布:宁夏干部网络学校 编辑:程序博客网 时间:2024/05/17 08:22

需要的头文件:

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

 

使用stat函数
    struct stat stat_buf;

    int ret;

    ret = stat("filename", &stat_buf);

    如果文件存在,则返回0。可以检查文件或目录。
原创粉丝点击