Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. how to check for a file/directory if the file has read only permissions

how to check for a file/directory if the file has read only permissions

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 2.9k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    Qt Enthusiast
    wrote on last edited by
    #1

    how to check for a file if the file has read only permissions or if the directory has read only permissions

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Use QFile::permissions()

      (Z(:^

      1 Reply Last reply
      3
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Take a look at QFileInfo

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        1
        • Q Offline
          Q Offline
          Qt Enthusiast
          wrote on last edited by
          #4

          but if the file has
          ls -al

          -r--r--r--

          how to check that file cannot be written any sample code

          1 Reply Last reply
          0
          • sierdzioS Offline
            sierdzioS Offline
            sierdzio
            Moderators
            wrote on last edited by
            #5
            const QFileInfo info("some/file");
            if (info.permission(QFile::WriteOwner | QFile::WriteGroup | QFile::WriteUser)) {
              // file is writable!
            } else {
              // file is read only
            }
            
            // Or even simpler:
            if (info.isWritable()) {
              // Yup
            } else {
              // Nope
            }
            

            (Z(:^

            1 Reply Last reply
            5

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved