PDA

View Full Version : How to check if user has permissions to create a file in a folder?



will49
11th September 2008, 16:26
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:


QFileInfo fi(my_folder_path);
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?

wysota
11th September 2008, 17:17
Have you seen this?

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.

will49
11th September 2008, 18:00
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?

wysota
11th September 2008, 20:08
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.