title: Delete a folder after deleting its content using c#
body: <p>I have created a temporary folder to keep some audio files. My intentions are to delete this temporary folder after joining the audio files into one file.</p>
  
  <p>Here is the part of my code that creates temporary files inside directory <code>directoryName</code>:</p>
  
  <pre><code>fileName = fileCounter.ToString() + ".wav";
  fileCounter++;
  fileName = directoryName + "\\" + fileName;
  </code></pre>
  
  <p>Code that joins all the temporary files is as follows:</p>
  
  <pre><code>public void Concatenate(string outputFile, List&lt;string&gt; sourceFiles)
  {
      byte[] buffer = new byte[1024];
      WaveFileWriter waveFileWriter = null;
      try
      {
          foreach (string sourceFile in sourceFiles)
          {
              using (WaveFileReader reader = new WaveFileReader(sourceFile))
              {
                  if (waveFileWriter == null)
                  {
                      // first time in create new Writer
                      waveFileWriter = new WaveFileWriter(outputFile, reader.WaveFormat);
                  }
                  else
                  {
                      if (!reader.WaveFormat.Equals(waveFileWriter.WaveFormat))
                      {
                          throw new InvalidOperationException("Can't concatenate WAV Files that don't share the same format");
                      }
                  }
  
                  int read;
                  while ((read = reader.Read(buffer, 0, buffer.Length)) &gt; 0)
                  {
                      waveFileWriter.WriteData(buffer, 0, read);
                  }
              }
          }
      }
      finally
      {
          if (waveFileWriter != null)
          {
              waveFileWriter.Dispose();
          }
      }
  }
  </code></pre>
  
  <p>I had help from this <a href="https://stackoverflow.com/questions/24371004/deleting-a-specific-folder-and-its-files-asp-net">question</a></p>
  
  <p>Here is my code to delete the files</p>
  
  <pre><code>private void DeleteDirectory()
  {
      string[] files = Directory.GetFiles(directoryName);
      foreach (string file in files)
      {
          File.Delete(file);
      }
      Directory.Delete(directoryName);            
  }
  </code></pre>
  
  <p>But the code in the question only deleted files inside the folder. But I want to delete the folder as well.</p>