4

如何使用 Boost 库将文件的权限更改为只读?

有些问题我已经看过了,比如thisthis,但是我还是不知道怎么做,我试过做

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

有任何想法吗?

4

2 回答 2

7
#include <boost/filesystem.hpp>

int main()
{
  using namespace boost::filesystem;
  wpath path = L"abc.txt";
  permissions(path, others_read|owner_read);
}
于 2013-05-29T11:01:11.993 回答
7

使用 boost 1.55,在 Windows 下,以下工作:

permissions(file_path, add_perms|owner_write|group_write|others_write);
于 2015-02-23T13:12:02.823 回答