title: How to delete folder containing files and sub folder properly in a MFC application
body: <p>I have a MFC application where I am facing a problem with folder delete. When I am deleting a folder along with all containing files, it shows deleted from application file list but it shows in Windows explorer but remains not-accessible.When I close the application it the folder vanishes from windows explorer. Why is this happening? I have seen <code>RemoveDirectory()</code> in the following code is returning zero. But if it is not deleted, then why does it goes away after closing the application. The function is as follows:</p>
  
  <pre><code>void SomeClass::DeleteFileFolder(CString filePath)
  {
  CFileFind finder;
  CString strWildcard(filePath);
  strWildcard += _T("\\*.*");
  CString str = "";
  
  BOOL bWorking = finder.FindFile(strWildcard);
  
  while (bWorking)
  {
      bWorking = finder.FindNextFile();
  
      if (finder.IsDots())
      {
          CString sFile = finder.GetFileName();
          if(sFile !="." &amp;&amp; sFile !="..")
          {
              CString sFile = finder.GetFileName();
              str = finder.GetFilePath();
              BOOL bDel = DeleteFile(str);
          }
      }
      else if (finder.IsDirectory())
      {
          CString sDir = finder.GetFileName();
          str = finder.GetFilePath();
          if((str !=".") &amp;&amp; (str !="..") &amp;&amp; (str != ".svn"))
          {
              DeleteFileFolder(str);
              BOOL bDel = RemoveDirectory(str); 
          }           
      }
      else
      {
          CString sFile = finder.GetFileName();
          str = finder.GetFilePath();
          BOOL bDel = DeleteFile(str);
      }
  }
  BOOL bDel = RemoveDirectory(filePath);
  finder.Close();
  </code></pre>
  
  <p>}</p>
  
  <p>Please guide.</p>