C中判断文件是否存在的access函数
来源:互联网 发布:xsplit直播软件下载 编辑:程序博客网 时间:2024/05/16 18:30
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 <io.h>
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> //android中可以省略掉.
- int file_exists(char *filename);
- int main(void)
- {
- printf("Does NOTEXIST.FIL exist: %s\n",
- file_exists("NOTEXISTS.FIL")? "YES" : "NO");
- return 0;
- }
- int file_exists(char *filename)
- {
- return (access(filename, 0)== 0);
- }
- C中判断文件是否存在的access函数
- C++(五) access函数判断文件是否存在
- C++ access函数判断文件是否存在
- access函数判断文件是否存在
- access:判断文件是否存在
- C语言函数access(szFilePath, 0)用于判断文件是否存在
- C中的access函数-- 判断文件是否存在及可读写等属性
- 在Visual foxpro 中判断文件是否存在的函数
- C/C++中判断一个文件是否存在的方法
- C语言中判断文件是否存在的方法详解
- linux下的access()函数判断文件是否存在、打印时间
- linux下的access()函数判断文件是否存在、打印时间
- linux下的access()函数判断文件是否存在、打印时间
- linux下的access()函数判断文件是否存在、打印时间
- linux 判断文件是否存在的access()方法与示例
- linux 判断文件是否存在的access()方法与示例
- linux 判断文件是否存在的access()方法与示例
- C 判断文件是否存在
- oracle rollup和cube
- NGUI研究之与EasyTouch结合使用
- [物理题] hdu 1155 Bungee Jumping
- 被虐中成长——2014年多校训练赛第一场解题报告
- 项目管理-技术论证会的组织实施注意要点
- C中判断文件是否存在的access函数
- hdu-2021-发工资喽 )
- uva 10050(线性表)
- UNIX域套接字
- atitit.获取北京时间CST 功能api总结 O7
- 答读者问(8):有关Java学习的相关问题
- 栈和堆的区别
- 也谈“圣人不死,大盗不止”
- Drag and drop into sandboxed App