Results 1 to 4 of 4

Thread: How to check if user has permissions to create a file in a folder?

  1. #1
    Join Date
    Jul 2007
    Posts
    56
    Thanks
    6
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default 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:

    Qt Code:
    1. QFileInfo fi(my_folder_path);
    2. bool can_write=fi.permission(QFile::WriteUser);
    To copy to clipboard, switch view to plain text mode 

    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?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to check if user has permissions to create a file in a folder?

    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.

  3. #3
    Join Date
    Jul 2007
    Posts
    56
    Thanks
    6
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default 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?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.