首页 > 数据库技术 > 详细

linux下的access()函数判断文件是否存在

时间:2014-10-21 14:57:31      阅读:481      评论:0      收藏:0      [点我收藏+]
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>

int main()
{
    if((access("test.c",F_OK))!=-1)
    {
        printf("文件 test.c 存在.\n");
    }
    else
    {
        printf("test.c 不存在!\n");
    }

    if(access("test.c",R_OK)!=-1)
    {
        printf("test.c 有可读权限\n");
    }
    else
    {
        printf("test.c 不可读.\n");
    }

    if(access("test.c",W_OK)!=-1)
    {
        printf("test.c 有可写权限\n");
    }
    else
    {
        printf("test.c 不可写.\n");
    }
    if(access("test.c",X_OK)!=-1)
    {
        printf("test.c 有可执行权限\n");
    }
    else
    {
        printf("test.c 不可执行.\n");
    }

    return 0;
}

linux下的access()函数判断文件是否存在

原文:http://www.cnblogs.com/liwentao1091/p/4040154.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!