分类: C/C++

int   access(const   char   *filename,   int   amode); 
amode参数为0时表示检查文件的存在性,如果文件存在,返回0,不存在,返回-1。 
这个函数还可以检查其它文件属性: 
06     检查读写权限 
04     检查读权限 
02     检查写权限 
01     检查执行权限 
00     检查文件的存在性
而这个就算这个文件没有读权限,也可以判断这个文件存在于否
存在返回0,不存在返回-1

C函数
  函数名: access 
  功 能: 确定文件的访问权限 
  用 法: int access(const char *filename, int amode);
[编辑本段]access
  Synopsis
  #include 
  int _access(const char *path,int mode) ;
  Description
  The access function, when used with files, determines whether the specified file exists and can be accessed as specified by the value of mode. When used with directories, _access determines only whether the specified directory exists; since under Windows all directories have read and write access.
  The mode argument can be one of :
  00 Existence only
  02 Write permission
  04 Read permission
  06 Read and write permission 
  Returns
  Zero if the file has the given mode, -1 if an error occurs.
  Portability :
  Windows. Under Unix a similar function exists too.
  Note that lcc-win32 accepts both _access (Microsoft convention) and access.
  程序例: 
  

#include <stdio.h>
  #include <io.h>
  int file_exists(char *filename);
  int main(void)
  {
  printf("Does NOTEXIST.FIL exist: %s\n",
  file_exists("NOTEXISTS.FIL") ? "YES" : "NO");
  return ;
  }
  int file_exists(char *filename)
  {
  return (access(filename, ) == );
  }

【转载】 C中的access函数的更多相关文章

  1. c++ 在Ubuntu系统中使用access函数

    include<iostream> #include<stdlib.h> #include<stdio.h> #include<unistd.h> us ...

  2. [转载]python中multiprocessing.pool函数介绍

    原文地址:http://blog.sina.com.cn/s/blog_5fa432b40101kwpi.html 作者:龙峰 摘自:http://hi.baidu.com/xjtukanif/blo ...

  3. 转载 --- SKLearn中预测准确率函数介绍

    混淆矩阵 confusion_matrix 下面将一一给出'tp','fp','fn'的具体含义: 准确率: 所有识别为"1"的数据中,正确的比率是多少. 如识别出来100个结果是 ...

  4. [转载]Oracle中的NVL函数

    Oracle中函数以前介绍的字符串处理,日期函数,数学函数,以及转换函数等等,还有一类函数是通用函数.主要有:NVL,NVL2,NULLIF,COALESCE,这几个函数用在各个类型上都可以. 下面简 ...

  5. [转载]MATLAB中神经网络的函数

    1.设计函数 solvein    设计线性网络:                solverb   设计径向基网络:                      solverbe    设计精确的径向 ...

  6. 【转载】 Sqlserver中查看自定义函数被哪些对象引用

    Sqlserver数据库中支持自定义函数,包含表值函数和标量值函数,表值函数一般返回多个数据行即数据集,而标量值函数一般返回一个值,在数据库的存储过程中可调用自定义函数,也可在该自定义函数中调用另一个 ...

  7. 转载:java中Thread.sleep()函数使用

    点我跳过黑哥的卑鄙广告行为,进入正文. Java多线程系列更新中~ 正式篇: Java多线程(一) 什么是线程 Java多线程(二)关于多线程的CPU密集型和IO密集型这件事 Java多线程(三)如何 ...

  8. 转载 为什么print在Python 3中变成了函数?

    转载自编程派http://codingpy.com/article/why-print-became-a-function-in-python-3/ 原作者:Brett Cannon 原文链接:htt ...

  9. 【转载】如何在 C#中访问 JavaScript函数?

    如何在 C#中访问 JavaScript函数? 时间:13-10-17 栏目:Unity3D教程 作者:zqcyou 评论:0     如何在 C#中访问 JavaScript函数?答案如下:c#代码 ...

随机推荐

  1. springmvc上传图片并显示图片--支持多图片上传

    实现上传图片功能在Springmvc中很好实现.现在我将会展现完整例子. 开始需要在pom.xml加入几个jar,分别是: <dependency> <groupId>comm ...

  2. js-JavaScript高级程序设计学习笔记2

    第四章 变量.作用域和内存问题 1.ES变量包含两种不同数据类型的值--基本类型值(5种基本数据类型)和引用类型值(保存在内存中的对象,所有引用类型值都是Object的实例) 2.只能给引用类型值动态 ...

  3. poj1379 模拟退火

    题意:和上题一样...就是把最小值换成了最大值.. ref:http://www.cppblog.com/RyanWang/archive/2010/01/21/106112.html #includ ...

  4. POJ2195 Going Home

    Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22091   Accepted: 11156 Description On ...

  5. Non Lasting Storage File System、procfs、sysfs

    catalog . 引言 . proc文件系统 . 简单的文件系统 . sysfs 0. 引言 传统上,文件系统用于在块设备上持久存储数据,但也可以使用文件系统来组织.提供.交换并不存储在块设备上的信 ...

  6. nagios note

    server: nagios nagios_plugin nrpe ip:192.168.1.2 client nagios_plugin xinetd nrpe ip:192.168.1.3 一篇介 ...

  7. 使用dnsmasq来提升CentOS上网速度

    1. 安装dnsmasq dnsmasq的官方网址是:http://www.thekelleys.org.uk/dnsmasq/doc.html.利用里面的下载链接下载dnsmasq-2.72.tar ...

  8. selenium.Phantomjs设置浏览器请求头

    from selenium import webdriver from selenium.webdriver.common.desired_capabilities import DesiredCap ...

  9. HDU 5908 Abelian Period(暴力+想法题)

    传送门 Description Let S be a number string, and occ(S,x) means the times that number x occurs in S. i. ...

  10. 深入浅出Redis02 使用Redis数据库(String类型)

    一 String类型 首先使用启动服务器进程 : redis-server.exe 1. Set 设置Key对应的值为String 类型的value. 例子:向 Redis数据库中插入一条数据类型为S ...