How to change file permissions using the Boost library?

mosg picture mosg · May 29, 2013 · Viewed 12.5k times · Source

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?

Answer

Igor R. picture Igor R. · May 29, 2013
#include <boost/filesystem.hpp>

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