How is it possible to check with the filesystem api, if a file is read only?

819 Views Asked by At

I would like to check, if a file is read only or writeable, possibly without actually opening it, using the new std::filesystem api.

I was able to find a documentation about permissions with an example code about how to query a specific file's owner/group/others read/write/exetuce permissions.

How is it possible to find out the read permission for the user that is running the program?

An other process could lock the file as well, which may also make it not writeable.

There is a similar question, but the answer uses a C api, which I would like to avoid.

1

There are 1 best solutions below

1
Roushan Raj On

Yes, it is. Read this documentatioin for detail.

here is a small snippet for same:

(std::filesystem::status(file_path).permissions() & std::filesystem::perms::owner_read != std::filesystem::perms::none) 

if val is true then, its readable.