title: Need to know if a directory has write permission or not in C++
body: <p>I need to know if a specified directory (local or shared path with login credentials) has write permissions or not.</p>
  
  <p>I am using GetFileAttributes but it always returns FILE_ATTRIBUTE_DIRECTORY and nothing else.</p>
  
  <p>My code is something like below</p>
  
  <pre><code>if(storageLocation != "")
  {
      //! check if local storage - user name password would be empty
      if(storageUsername == "" &amp;&amp; storagePassword == "")
      {
          //! local storage
          //! lets check whether the local path is a valid path or not
          boost::filesystem::path fpath(storageUsername.c_str());
          if(boost::filesystem::exists(fpath))
          {
              DWORD attrib = ::GetFileAttributes(storageLocation.c_str());
              if((attrib != INVALID_FILE_ATTRIBUTES) &amp;&amp; 
                ((attrib &amp; FILE_ATTRIBUTE_READONLY) != FILE_ATTRIBUTE_READONLY))
              {
                  string strWritePermission = "TRUE";
              }
          }
      }
      else
      {
          uncLocation_t uncLocation;
          uncLocation.m_location = storageLocation;
          uncLocation.m_username = storageUsername;
          uncLocation.m_password = storagePassword;
          if(0 == connectToUNCLocation(uncLocation)) // My function to connect to UNC location
          {
              //! successful connection
              DWORD attrib = ::GetFileAttributes(storageLocation.c_str());
              if((attrib != INVALID_FILE_ATTRIBUTES) &amp;&amp; 
                 ((attrib &amp; FILE_ATTRIBUTE_READONLY) != FILE_ATTRIBUTE_READONLY))
              {
                  string strWritePermission = "TRUE";
              }
          }
      }
  }
  </code></pre>
  
  <p>I don't understand why but GetFileAttributes always return 0x16.</p>
  
  <p>I have tested it by creating a shared folder and creating 2 folders in it. One with read only permissions and other with default permissions. But in all 3 cases (shared folder, read only folder and default permission folder) I am getting same return value.</p>
  
  <p>There is on way to find write permission, to create a temporary file (usinf CreateFile in GENERIC_WRITE mode) and if successfully created, delete it. But I don't want to use this method as I don't want my application to create a temporary file each time user specifies a location.</p>
  
  <p>Please suggest what should be done.</p>