How to change file permissions using the Boost library?

13,400

Solution 1

#include <boost/filesystem.hpp>

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

Solution 2

With boost 1.55, under Windows, the following works:

permissions(file_path, add_perms|owner_write|group_write|others_write);
Share:
13,400
mosg
Author by

mosg

/* May all your PUSHs be POPed */

Updated on June 14, 2022

Comments

  • mosg
    mosg almost 2 years

    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?

  • mosg
    mosg almost 11 years
    I'm using boost 1.44 and there is no permissions in boost::filesystem namespace...
  • Igor R.
    Igor R. almost 11 years
    @mosg Well, the links you provided pointed to the docs from 1.49. If you use earlier version, you most likely can't set permissions. Note however that 1.44 is ~3 years old...
  • mosg
    mosg almost 11 years
    Yes, It's my fault, didn't mentioned boost version. Thanks anyway!