函数原型
int _access( const char *path, int mode );
int _waccess( const wchar_t *path, int mode );
Parameters
path
File or directory path
mode
Permission setting
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 |
_waccess is a wide-character version of _access; the path argument to _waccess is a wide-character string. _waccess and _access behave identically otherwise.
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" );
}
}
以上内容为转载 http://zjtang.bokee.com/viewdiary.16219398.html
Example2:
if((access( filename, 0 )) == -1) {
// file is not existed
}
else {
// file is not existed
}