Search code examples
c++boostpermissionsboost-filesystem

C++/boost: checking process permission


I'm writting a C++ program in order to make some static analyse and modifications over a website. I don't change the project files, but the files are copied, analysed and modified in a new folder.

Is there a way of checking, for example, using boost::filesystem, if I (the program/the user executing it) have permissions enough to read (files), execute (for processing the directory hierarchy) and write (files or create new folders) on a current folder and its files (or at least under unix systems)?


Solution

  • No, you can not check file permissions with boost program options library. File permissions can be queried with boost filesystem library:

    #include <boost/filesystem.hpp> 
    #include <stdio.h> 
    
    namespace bfs=boost::filesystem;
    
    int main(int argc,char * argv[])
    {
        if (argc < 2) 
            return;
    
        bfs::path p(argv[1]);
        bfs::file_status s = status(p);
        printf("%X\n",s.permissions());
    }
    

    The values of permissions flags are as enum perms in boost/filesystem/v3/operations.hpp