用_access判断文件或文件夹是否存在及其读写权限
来源:互联网 发布:百度自然搜索排名优化 编辑:程序博客网 时间:2024/06/08 05:49
摘自MSDN,以前一直没用过这个函数,今天调试程序发现了这个函数,感觉挺好用,尤其是判断一个文件或文件夹是否存在的时候,用不着再find了,文件的话还可以检测读写权限,文件夹的话则只能判断是否存在
int _access( const char *path, int mode );
Return Value
Each of these functions returns 0 if the file has the given mode. The function returns –1 if the named file does not exist or is not accessible in the given mode; in this case, errno is set as follows:
EACCES
Access denied: file’s permission setting does not allow specified access.
ENOENT
Filename or path not found.
Parameters
path
File or directory path
mode
Permission setting
Remarks
When used with files, the _access function 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; in Windows NT, all directories have read and write access.
mode Value Checks File For
00 Existence only
02 Write permission
04 Read permission
06 Read and write permission
Example
/* ACCESS.C: This example uses _access to check the * file named "ACCESS.C" to see if it exists and if * writing is allowed. */#include <io.h>#include <stdio.h>#include <stdlib.h>void main( void ){ /* Check for existence */ if( (_access( "ACCESS.C", 0 )) != -1 ) { printf( "File ACCESS.C exists/n" ); /* Check for write permission */ if( (_access( "ACCESS.C", 2 )) != -1 ) printf( "File ACCESS.C has write permission/n" ); }}
Output
File ACCESS.C existsFile ACCESS.C has write permission
- 用_access判断文件或文件夹是否存在及其读写权限
- _access判断文件是否存在
- _access()函数检测文件或文件夹是否存在,_mkdir()创建目录。
- _access的用法(判断文件夹是否存在)
- 判断文件或文件夹是否存在
- 判断文件或文件夹是否存在
- 判断文件或文件夹是否存在
- 判断文件或文件夹是否存在
- 判断文件或文件夹是否存在
- 判断文件夹或文件是否存在
- Java判断文件或文件夹是否存在
- python判断文件或文件夹是否存在
- golang判断文件或文件夹是否存在
- VC++判断文件或文件夹是否存在
- shell判断文件或文件夹是否存在
- VC++ 判断文件或文件夹是否存在
- golang判断文件或文件夹是否存在
- 用VBA判断指定的文件夹或文件是否存在
- Eclipse、JBoss、MySQL
- 搜集:C# VB 语法对比图
- VCore, VDD, VDDQ, VDDR, VDIMM.. Help!
- 剖析Delphi中的构造和析构
- 突然发现,我给csdn的贡献很大啊!
- 用_access判断文件或文件夹是否存在及其读写权限
- 现在,linux何去何从
- 新游戏中出现的基于BSP场景分割技术
- 程序中获得配置文件输入流和输出流的通用方法
- 关于微软的摔XBOX的问题
- 汽车之家和pcpop的ceo--李想:创业可以毁掉一个人的一辈子
- SOA资源
- 使用C#的反射机制时遇到的问题
- 如何实现一个BTE