另一种判断文件存在的方法--_access和_waccess
来源:互联网 发布:数据库同步工具 编辑:程序博客网 时间:2024/06/14 11:10
_access, _waccess
Determine file-access permission.
int _access( const char *path, int mode );
int _waccess( const wchar_t *path, intmode );
RoutineRequired HeaderOptional HeadersCompatibility_access<io.h><errno.h>Win 95, Win NT_waccess<wchar.h> or <io.h><errno.h>Win NT
For additional compatibility information, see Compatibility in the Introduction.
Libraries
LIBC.LIBSingle thread static library, retail versionLIBCMT.LIBMultithread static library, retail versionMSVCRT.LIBImport library for MSVCRT.DLL, retail version
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 ofmode. When used with directories, _access determines only whether the specified directory exists; in Windows NT, all directories have read and write access.
mode ValueChecks File For00Existence only02Write permission04Read permission06Read and write permission
_waccess is a wide-character version of _access; thepath argument to _waccess is a wide-character string. _waccess and _access behave identically otherwise.
Generic-Text Routine Mappings
TCHAR.H Routine _UNICODE & _MBCS Not Defined_MBCS Defined_UNICODE Defined_taccess_access_access_waccess
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"
);
if
( (_access(
"ACCESS.C"
, 4 )) != -1 )
printf
(
"File ACCESS.C has read permission\n"
);
if
( (_access(
"ACCESS.C"
, 6 )) != -1 )
printf
(
"File ACCESS.C has read and write permission\n"
);
}
else
{
printf
(
"File ACCESS.C does not exists\n"
);
}
}
- 判断文件是否存在的另一种方法 _access 和 _waccess
- 另一种判断文件存在的方法--_access和_waccess
- _access, _waccess 确定文件的访问权限
- C++ _access和_waccess的使用方法
- C++ _access和_waccess的使用方法
- c++ _waccess 和_access
- _access判断文件是否存在
- Windows下使用_access和_stat判断文件和目录是否存在的区别
- _access的用法(判断文件夹是否存在)
- _access判断文人提否存在
- 用_access判断文件或文件夹是否存在及其读写权限
- Python判断文件和文件夹是否存在的方法
- Python判断文件和文件夹是否存在的方法
- Python判断文件和文件夹是否存在的方法
- Python判断--文件和文件夹--是否存在的方法
- Python判断文件和文件夹是否存在的方法
- Python判断文件和文件夹是否存在的方法
- Python判断文件和文件夹是否存在的方法
- 08_旋转数组的最小数字
- int 和 integer 的区别
- ActivityThread类
- MongoDB
- Java 之 FileReader FileInputStream InputStreamReader BufferedReader 作用与区别
- 另一种判断文件存在的方法--_access和_waccess
- 安装完Hadoop之后,命令行输入hadoop却找不到命令
- CoreML学习——转换caffe模型并应用到 iOS App中
- TP框架Hook的使用
- 3-1 对表进行聚合查询
- leetcode_7_Reverse Integer
- JNI开发之访问java的实例
- React中文
- python学习日志--day2