How to check if user has permissions to create a file in a folder?
I need to check if a user has permissions to create a new file in a folder (i.e. has write access).
I was using:
Code:
bool can_write
=fi.
permission(QFile::WriteUser);
But that seems to return based on if the user has permission to write to the folder name itself (i.e. rename it), rather than to write a file inside that folder.
What is the best way to do what I need?
Maybe try creating a temporary file and see if it fails?
Re: How to check if user has permissions to create a file in a folder?
Have you seen this?
Quote:
Warning: Because of differences in the platforms supported by Qt, the semantics of ReadUser, WriteUser and ExeUser are platform-dependent: On Unix, the rights of the owner of the file are returned and on Windows the rights of the current user are returned. This behavior might change in a future Qt version.
Re: How to check if user has permissions to create a file in a folder?
Yes I saw that, but the issue I have is that i need the permission for creating a file in the folder, not the permission on the folder.
So should I take that to mean the only real way to check if a user (on all platforms) can create a file is to actually try creating a temporary file and see if it fails?
Re: How to check if user has permissions to create a file in a folder?
Permission to create a file in a folder should be equal to permission of writing a folder. If you can afford creating a file, then go ahead, but for some cases it would be a really bad idea.