函数原形
int _access( const char *path, int mode ); int _waccess( const wchar_t *path, int mode );
返回值:
参数:
mode value | Checks file for |
---|---|
00 | Existence only |
02 | Write-only |
04 | Read-only |
06 | Read and write |
实例代码:
判断文件存在与否,判断文件是否只读.
#include <io.h> #include <stdio.h> #include <stdlib.h> int main( void ) { // Check for existence. if( (_access( "crt_ACCESS.C", 0 )) != -1 ) { printf_s( "File crt_ACCESS.C exists.\n" ); // Check for write permission. // Assume file is read-only. if( (_access( "crt_ACCESS.C", 2 )) == -1 ) printf_s( "File crt_ACCESS.C does not have write permission.\n" ); } }
输出:
File crt_ACCESS.C exists. File crt_ACCESS.C does not have write permission. |