转自: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. js转换 /Date(1464671903000)/ 格式的日期的方法

    转换成:2016-07-11 function getFDate(date) { var d = eval('new ' + date.substr(1, date.length - 2)); var ...

  2. Inno Setup 教程

    参考博客:制作部署安装包:Inno Setup 参考资料:Inno Setup详细教程 参考资料:Innosetup使用详细全面教程 个人使用的 风铃夜思雨 的汉化版,版本:5.5.5 ; 脚本由 I ...

  3. RouterOS软路由设置固定IP+PPPOE

    内网: IP:192.168.10.254/24 网关:192.168.10.254 外网: IP:218.17.172.17/28 子网掩码:255.255.255.240 网关:218.17.17 ...

  4. Oracle RAC 11.2.0.4 – RHRL 6.4: DiskGroup resource are not running on nodes. Database instance may not come up on these nodes

    使用DBCA创建新库的时候报错: 查看资源状态: $ crsctl stat res -t ------------------------------------------------------ ...

  5. python之django 资料

    里边有不少比较好的文章. http://www.cnblogs.com/luxiaojun/p/5795070.html

  6. 怎么设置task的最大线程数

    //-------------------------------------------------------------------------- // // Copyright (c) Mic ...

  7. IntelliJ IDEA 缓存和索引介绍和清理方法

    IntelliJ IDEA 首次加载项目的时候,都会创建索引,而创建索引的时间跟项目的文件多少成正比,我也简单强调了 IntelliJ IDEA 索引的重要性.这里我们再对此进行详细说明索引.缓存对 ...

  8. typedef NS_OPTIONS 位移的枚举

    typedef NS_OPTIONS里面的枚举可以并存使用  用 | 来并存

  9. 删除NSMutableArray中的二维数组

    // 删除模型数据 [self.mutableArr[indexPath.section] removeObjectAtIndex:indexPath.row]; //删除UI(刷新数据,UI) [s ...

  10. 快速搭建企业subversion

    快速搭建企业subversion 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 我们公司用的版本控制控制系统就是subversion(简称SVN),不得不说这是一款比较好使的管理工 ...