title: Delete folder and all subfolders plus files
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/925192/recursive-delete-of-files-and-directories-in-c-sharp">Recursive delete of files and directories in C#</a>  </p>
  </blockquote>
  
  
  
  <p>I am trying to delete all files and folders in a root folder but my program keeps crashing because some files are over the 256 or something limit.</p>
  
  <p>What I need to do is go to the last folder delete all the files and then delete that folder and work my way upto the root folder and then delete that.</p>
  
  <p>I'm stuck on how to do this please can someone help with a simple way to do this?</p>
  
  <p>many thanks for any help</p>
  
  <p>I'm using C#,
  the code is: </p>
  
  <pre><code>    private void RemoveDirectory(DirectoryInfo directory)
      {
          RemoveReadOnly(directory);
  
          directory.Delete(true);
  
          bool directoryExists = true;
  
          while (directoryExists)
              directoryExists = Directory.Exists(directory.FullName);
  
          SendProgressMessage(string.Format("Removed {0}", directory.FullName));
      }
  </code></pre>