How to get file permissions with c++ boost library?

前端 未结 2 509
我在风中等你
我在风中等你 2021-01-18 14:50

I am working on a project to make a database of the files I have on current directory. And one of the details I want about my files is the file permissions that are set with

相关标签:
2条回答
  • 2021-01-18 15:14
    perms      permissions() const                { return m_perms; } 
    

    defined in boost/filesystem/v3/operations.hpp

    Add an easy sample code

    #include <boost/filesystem.hpp> 
    #include <stdio.h> 
    namespace fs=boost::filesystem;
    int main(int argc,char * argv[]){
        fs::path p(argv[1]);
        fs::file_status s = status(p);
        printf("%o\n",s.permissions());
    }
    
    0 讨论(0)
  • 2021-01-18 15:15

    File permissions example for windows:

    unsigned long attributes = ::GetFileAttributes( filePath.file_string().c_str());
    
    if ( attributes != 0xFFFFFFFF && ( attributes & FILE_ATTRIBUTE_READONLY ))
    {
        attributes &= ~FILE_ATTRIBUTE_READONLY;
        ::SetFileAttributes( filePath.file_string().c_str(), attributes );
    }
    
    0 讨论(0)
提交回复
热议问题