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 permission |
04 |
Read permission |
06 |
Read and write permission |
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:
下面是随便写了个程序测试一下。。
#include<iostream>
#include <io.h>
#include<string>
using namespace std;
int main()
{
if(access("D:\\1.txt",0)!=-1)
{
cout<<"该文件存在"<<endl;
if(access("D:\\1.txt",2)!=-1)
{
cout<<"Write Permission"<<endl;
}
if(access("D:\\1.txt",4)!=-1)
{
cout<<"Read Permission"<<endl;
}
if(access("D:\\1.txt",6)!=-1)
{
cout<<"Write and Read Permission"<<endl;
}
}
else
{
cout<<"该文件不存在"<<endl;
}
return 0;
}