如何使用Boost库更改文件权限? [英] How to change file permissions using the Boost library?

查看:840
本文介绍了如何使用Boost库更改文件权限?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我已经看到了一些问题,例如< a href =http://www.boost.org/doc/libs/1_49_0/libs/filesystem/v3/doc/reference.html#last_write_time =nofollow> this 和,但我还是不知道如何做到,我已经尝试过

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

任何想法?

推荐答案

#include <boost/filesystem.hpp>

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

这篇关于如何使用Boost库更改文件权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆