如何使用Boost库将文件的权限更改为只读?
我已经看过一些问题,例如this和this,但我仍然不知道该怎么做,我已经尝试过了
boost::filesystem::wpath path = L"abc.txt";
if( boost::filesystem::exists( path ) && boost::filesystem::is_regular_file( path ) )
{
boost::filesystem::file_status s = boost::filesystem::status( path );
/* here I need to set file permissitons to READ ONLY for `path` file */
}
有什么想法吗?
答案 0 :(得分:6)
#include <boost/filesystem.hpp>
int main()
{
using namespace boost::filesystem;
wpath path = L"abc.txt";
permissions(path, others_read|owner_read);
}
答案 1 :(得分:5)
使用boost 1.55,在Windows下,以下工作:
permissions(file_path, add_perms|owner_write|group_write|others_write);