code: public function remove($recursive = false)
      {
          if (! $this->exists()) {
              return;
          }
          
          if ($this->isEmpty()) {
              if (rmdir($this->path) === false) {
                  throw new DirectoryException("Could not remove directory {dir}", array(
                      'dir' => $this->path
                  ));
              }
              return;
          }
          
          if (! $recursive) {
              throw new DirectoryException("Directory {dir} is not empty", array(
                  'dir' => $this->path
              ));
          }
          
          $iter = new \DirectoryIterator($this->path);
          while ($iter->valid()) {
              if ($iter->isDot()) {
                  $iter->next();
                  continue;
              }
              
              if ($iter->isDir()) {
                  $dir = new Directory($iter->getPathname());
                  $dir->remove(true);
              } else {
                  unlink($iter->getPathname());
              }
              
              $iter->next();
          }
          rmdir($this->path);
      }
docs: Remove a directory
  
  @param boolean $recursive
  Whether to remove it if its not empty
  
  @throws DirectoryException