// access() 函数判断一个文件的存在和用户对此文件的权限
#include <iostream>
#include <io.h> // for access
#include <string>
using namespace std;
int main()
{
char * filename = "C:\\test.txt";
if(access(filename, 0) != -1)
{
cout << "file exist." << endl;
if(access(filename, 2) != -1)
cout << "write permission" << endl;
//else
//cout << "write not permission" << endl;
if(access(filename, 4) != -1)
cout << "read permission" << endl;
//else
//cout << "read not permission" << endl;
if(access(filename, 6) != -1)
cout << "write and read permission" << endl;
}
else
cout << "file not exist." << endl;
system("pause");
return 0;
}
判断用户对某个磁盘文件的读写权限
最新推荐文章于 2021-08-06 13:06:05 发布