title: Removing read only attribute on a directory using C#
body: <p>I was successfully able to remove read only attribute on a file using the following code snippet:</p>
  
  <p>In main.cs</p>
  
  <pre><code>FileSystemInfo[] sqlParentFileSystemInfo = dirInfo.GetFileSystemInfos();
  
  foreach (var childFolderOrFile in sqlParentFileSystemInfo)
  {
      RemoveReadOnlyFlag(childFolderOrFile);
  }
  
  private static void RemoveReadOnlyFlag(FileSystemInfo fileSystemInfo)
  {
      fileSystemInfo.Attributes = FileAttributes.Normal;
      var di = fileSystemInfo as DirectoryInfo;
  
      if (di != null)
      {
          foreach (var dirInfo in di.GetFileSystemInfos())
              RemoveReadOnlyFlag(dirInfo);
      }
  }
  </code></pre>
  
  <p>Unfortunately, this doesn't work on the folders. After running the code, when I go to the folder, right click and do properties, here's what I see:</p>
  
  <p><img src="https://i.stack.imgur.com/63CBg.gif" alt="alt text"></p>
  
  <p>The read only flag is still checked although it removed it from files underneath it. This causes a process to fail deleting this folder. When I manually remove the flag and rerun the process (a bat file), it's able to delete the file (so I know this is not an issue with the bat file)</p>
  
  <p>How do I remove this flag in C#?</p>