热门标签 | HotTags
当前位置:  开发笔记 > 开发工具 > 正文

C中的access函数

intaccess(constchar*filename,intamode);amode参数为0时表示检查文件的存在性,如果文件存在,返回0,不存在,返回-1。这个函数还可以检查其它文件属性:06检查读写权限04检查读权限02检查写权限01检查执行权限00检查文件的存在性而这个

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

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.
  程序例:
  

  1. #include <stdio.h>
  2.   #include <io.h>
  3.   int file_exists(char *filename);
  4.   int main(void)
  5.   {
  6.   printf("Does NOTEXIST.FIL exist: %s\n",
  7.   file_exists("NOTEXISTS.FIL") ? "YES" : "NO");
  8.   return 0;
  9.   }
  10.   int file_exists(char *filename)
  11.   {
  12.   return (access(filename, 0) == 0);
  13.   }

推荐阅读
author-avatar
你是我最终的荒唐
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有