title: removing directories and all sub-directories in it
body: <p>I wrote a function which should delete a directory and all files and folders in it, but it got some troubles.
  For my targets, I made special directory for experiments. This directory stores some files and one folder. And this folder (sub-directory) also contains 1 or 2 files. My function successfuly removes sub-directory and all files in it. And all files in main directory are also removes successfuly. But when the function starts to remove main directory - it fails. It seems like rmdir returns not 0 and I dont know why, cause sub directory removes well. </p>
  
  <p><strong>As an argument it takes string like "D:\new\".</strong></p>
  
  <p>Where new is main directory that should be removed whith everything in it. 
  <em>Here is code of this function:</em></p>
  
  <pre><code> void OperationsWithDirectories::RemovingCycle(string _path)
      {
          string wayToFile;           // string to hold the path to the directory without mask 
          string deletedFile;         // string which would hold the way to deleting file
          wayToFile = _path;
  
          _path += "*.*";             // add a mask to the _path string
  
  
          _finddata_t* fileinfo = new _finddata_t;
  
          long done = _findfirst(_path.c_str(), fileinfo);
  
          int IsContinue = done;
  
  while (IsContinue != -1)
  {
      deletedFile = wayToFile + fileinfo-&gt;name;
  
      if (fileinfo-&gt;attrib == _A_SUBDIR)
      {
          if (strcmp(fileinfo-&gt;name, ".") != 0 &amp;&amp; strcmp(fileinfo-&gt;name, "..") != 0)
          {
              cout &lt;&lt; "\nEnter subdirectory\n";
              RemovingCycle(wayToFile + fileinfo-&gt;name + "\\");       //recursive func wich would start, if subdirectory is exist
              cout &lt;&lt; "\nOutta subdirectory\n";
          }
      }
      else
      {
          if ((remove(deletedFile.c_str())) != 0)
              cout &lt;&lt; "\n\n ERROR IN FILE DELETING\n\n";
          else
              cout &lt;&lt; endl &lt;&lt; deletedFile &lt;&lt; " - was deleted";
      }
  
      IsContinue = _findnext(done, fileinfo);
  }
  
  if ((_rmdir(wayToFile.c_str())) != 0)
      cout &lt;&lt; "\n\nERROR IN DIRECT - " &lt;&lt; wayToFile &lt;&lt; " DELETING\n\n";
  else
      cout &lt;&lt; "\ndir - " &lt;&lt; wayToFile &lt;&lt; " was deleted succesfully\n";
  </code></pre>
  
  <p>}</p>