How to change file permissions using the Boost library?

前提是你 提交于 2019-12-10 15:27:22

问题


How can I use the Boost library to change the permissions of a file to read-only?

There are some questions that I have already seen, such as this and this, but I still don't know how to do it, I have tried doing

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 */
}

Any ideas?


回答1:


#include <boost/filesystem.hpp>

int main()
{
  using namespace boost::filesystem;
  wpath path = L"abc.txt";
  permissions(path, others_read|owner_read);
}



回答2:


With boost 1.55, under Windows, the following works:

permissions(file_path, add_perms|owner_write|group_write|others_write);


来源:https://stackoverflow.com/questions/16810982/how-to-change-file-permissions-using-the-boost-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!