转自:http://blog.csdn.net/kingjo002/article/details/8442146

一、access函数
功能描述:
检查调用进程是否可以对指定的文件执行某种操作。 用法:
#include <unistd.h>
#include <fcntl.h> int access(const char *pathname, int mode); 参数:
pathname: 需要测试的文件路径名。
mode: 需要测试的操作模式,可能值是一个或多个R_OK(可读?), W_OK(可写?), X_OK(可执行?) 或 F_OK(文件存在?)组合体。 返回说明:
成功执行时,返回0。失败返回-,errno被设为以下的某个值
EINVAL: 模式值无效
EACCES: 文件或路径名中包含的目录不可访问
ELOOP : 解释路径名过程中存在太多的符号连接
ENAMETOOLONG:路径名太长
ENOENT: 路径名中的目录不存在或是无效的符号连接
ENOTDIR: 路径名中当作目录的组件并非目录
EROFS: 文件系统只读
EFAULT: 路径名指向可访问的空间外
EIO: 输入输出错误
ENOMEM: 不能获取足够的内核内存
ETXTBSY:对程序写入出错 #include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h> int main()
{
if((access("test.c",F_OK))!=-)
{
printf("文件 test.c 存在.\n");
}
else
{
printf("test.c 不存在!\n");
} if(access("test.c",R_OK)!=-)
{
printf("test.c 有可读权限\n");
}
else
{
printf("test.c 不可读.\n");
} if(access("test.c",W_OK)!=-)
{
printf("test.c 有可写权限\n");
}
else
{
printf("test.c 不可写.\n");
}
if(access("test.c",X_OK)!=-)
{
printf("test.c 有可执行权限\n");
}
else
{
printf("test.c 不可执行.\n");
} return ;
} #include <stdio.h>
#include <time.h>
int main()
{
time_t now = time(NULL);
char buf[];
strftime(buf,,"%Y%m%d",localtime(&now));
printf("%s\n",buf); strftime(buf,,"%Y-%m-%d %H:%M:%S",localtime(&now));
printf("%s\n",buf); strftime(buf,,"%y%m%d %H:%M:%S",localtime(&now));
printf("%s\n",buf); strftime(buf,,"%y%m%d",localtime(&now));
printf("%s\n",buf); strftime(buf,,"%H:%M:%S",localtime(&now));
printf("%s\n",buf);
return ;
}

linux C判断文件是否存在【转】的更多相关文章

  1. linux shell判断文件,目录是否存在或者具有权限

    在linux中判断文件,目录是否存在或则具有的权限,根据最近的学习以及网上的资料,进行了以下的总结: #!/bin/sh myPath="/var/log/httpd/" myFi ...

  2. Linux shell判断文件和文件夹是否存在

    shell判断文件,目录是否存在或者具有权限 #!/bin/sh myPath="/var/log/httpd/" myFile="/var /log/httpd/acc ...

  3. [转] Linux shell判断文件和文件夹是否存在

    shell判断文件,目录是否存在或者具有权限 #!/bin/sh myPath="/var/log/httpd/" myFile="/var /log/httpd/acc ...

  4. linux下判断文件和目录是否存在[总结]

    1.前言 工作中涉及到文件系统,有时候需要判断文件和目录是否存在.我结合APUE第四章文件和目录,总结一下如何正确判断文件和目录是否存在,方便以后查询. 2.stat系列函数 stat函数用来返回与文 ...

  5. linux下判断文件和目录是否存在

    1.前言 工作中涉及到文件系统,有时候需要判断文件和目录是否存在.我结合APUE第四章文件和目录,总结一下如何正确判断文件和目录是否存在,方便以后查询. 2.stat系列函数 stat函数用来返回与文 ...

  6. linux shell 判断文件是否存在等符号

    -a file exists.  -b file exists and is a block special file.  -c file exists and is a character spec ...

  7. Linux shell判断文件和文件夹是否存在(转发)

    #!/bin/sh myPath="/var/log/httpd/" myFile="/var /log/httpd/access.log" #这里的-x 参数 ...

  8. linux C判断文件是否存在

    access函数 功能描述: 检查调用进程是否可以对指定的文件执行某种操作.   用法: #include <unistd.h> #include <fcntl.h> int ...

  9. linux c 判断文件存在,遍历文件,随机修改文件内容

    #include<stdio.h> #include<stdlib.h> #include<time.h> #include<assert.h> #in ...

随机推荐

  1. 利用css做扇形

    html和css每一块的边边角角都是直来直去,除了border-raius,要怎么做扇形了?当然,你如果只想要得到直角扇形,和半圆,那就很简单?那么做小于180的直角扇形,如何做了(大于180的直角无 ...

  2. POJ 1528问题描述

    Description From the article Number Theory in the 1994 Microsoft Encarta: ``If a, b, c are integers ...

  3. Android 使用shape来画线

    注意:Android3.0以上系统开始支持硬件加速特性hardwareAccelerated,默认是启用的.当你的某个activity用到了“虚线”效果的时候,必须要设置AndroidManifest ...

  4. android中actionbar的title居中

    1.配置 activity的主题: android:theme="@style/AppThemeBB" 2. 通过Menu.xml文件布局 添加菜单item menu/menu.x ...

  5. python_类

    1. 对象的概念 对象包括特性和方法.特性只是作为对象的一部分的变量,方法则是存储在对象内的函数.对象中的方法和其他函数的区别在于方法总是将对象作为自己的第一个参数,这个参数一般称为self. 2. ...

  6. Vue.2.0.5-事件处理器

    监听事件 可以用 v-on 指令监听 DOM 事件来触发一些 JavaScript 代码. 示例: <div id="example-1"> <button v- ...

  7. EBS运行快速安装的程序时,提示DISPLAY变量设置不对

    EBS运行快速安装的程序时,系统提示如下: Rapid Install Wizard is validating your file system...... >> Wizard requ ...

  8. mongodb查询文档

    说到查询,我们一般就想起了关系型数据库的查询了,比如:order by(排序).limit(分页).范围查询(大于某个值,小于某个值..,in查询,on查询,like查询等待很多),同样mongodb ...

  9. PostgreSQL Replication之第十三章 使用PL/Proxy扩展(3)

    13.3 聪明地扩展与处理集群 建立集群不是您面临的唯一任务.如果所有的事情都做完了并且系统已经运行了,您可能需要到处调整配置. 13.3.1 添加和移动分区 一旦一个集群启动并运行,您可能会发现您的 ...

  10. Leetcode: Self Crossing

    You are given an array x of n positive numbers. You start at point (0,0) and moves x[0] metres to th ...