Recursively Remove directories if the system allows.

@param string|null $path Path of directory to delete
@return bool Success
168766
public function delete($path = null)
    {
        if (!$path) {
            $path = $this->pwd();
        }
        if (!$path) {
            return false;
        }
        $path = Folder::slashTerm($path);
        if (is_dir($path)) {
            try {
                $directory = new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::CURRENT_AS_SELF);
                $iterator = new RecursiveIteratorIterator($directory, RecursiveIteratorIterator::CHILD_FIRST);
            } catch (Exception $e) {
                return false;
            }

            foreach ($iterator as $item) {
                $filePath = $item->getPathname();
                if ($item->isFile() || $item->isLink()) {
                    //@codingStandardsIgnoreStart
                    if (@unlink($filePath)) {
                        //@codingStandardsIgnoreEnd
                        $this->_messages[] = sprintf('%s removed', $filePath);
                    } else {
                        $this->_errors[] = sprintf('%s NOT removed', $filePath);
                    }
                } elseif ($item->isDir() && !$item->isDot()) {
                    //@codingStandardsIgnoreStart
                    if (@rmdir($filePath)) {
                        //@codingStandardsIgnoreEnd
                        $this->_messages[] = sprintf('%s removed', $filePath);
                    } else {
                        $this->_errors[] = sprintf('%s NOT removed', $filePath);

                        return false;
                    }
                }
            }

            $path = rtrim($path, DIRECTORY_SEPARATOR);
            //@codingStandardsIgnoreStart
            if (@rmdir($path)) {
                //@codingStandardsIgnoreEnd
                $this->_messages[] = sprintf('%s removed', $path);
            } else {
                $this->_errors[] = sprintf('%s NOT removed', $path);

                return false;
            }
        }

        return true;
    }
742536
public static function deleteDirRecursively($path)
    {
        if (! $paths = self::getFilesFromDir($path)) {
            return false;
        }

        foreach ($paths as $file) {
            if ($file->isFile()) {
                if (! self::delete($file->getRealPath())) {
                    return false;
                }
            } elseif (! $file->isDot() && $file->isDir()) {
                self::deleteDirRecursively($file->getRealPath());
                self::deleteEmptyDir($file->getRealPath());
            }
        }

        return self::deleteEmptyDir($path);
    }
265361
public function delete($path)
  {
    $result = false;
    $parts = $this->split($path);

    $name = array_shift($parts);
    if (!sizeof($parts)) {
      if (isset($this->_ownData[$name])) {
        unset($this->_ownData[$name]);
        $result = true;
      }
    } elseif (isset($this->_subTrees[$name])) {
      $subtree = $this->_subTrees[$name];
      /* @var $subtree Wrapper_FS_Changes */

      $result = $subtree->delete($parts);
      if ($result && !$subtree->count()) {
        unset($this->_subTrees[$name]);
      }
    }

    return $result;
  }
129754
public function emptyDir($path,$except = Array()){

        try {

            $iterator = new \DirectoryIterator($path);

            foreach ($iterator as $file){

                if($file->isDot() || in_array($file->getPathname(),$except)){
                    continue;
                }//if

                if($file->isDir() && (!$this->emptyDir($file->getPathname()) || !rmdir($file->getPathname()))){
                    return false;
                }//if

                if($file->isFile() && !unlink($file->getPathname())){
                    return false;
                }//if

            }//foreach

        } catch (\Exception $e){
            error_log($e->getMessage());
            return false;
        }//catch

        return true;

    }
783024
protected function clearDirectory($path)
    {
        $iterator = new \DirectoryIterator($path);

        /** @var \DirectoryIterator $fileinfo */
        foreach ($iterator as $fileinfo) {
            if ($fileinfo->isDot()) {
                continue;
            }

            if ($fileinfo->isFile() || $fileinfo->isLink()) {
                @unlink($fileinfo->getPathname());
            } elseif ($fileinfo->isDir()) {
                $this->clearDirectory($fileinfo->getPathname());
            }
        }
    }
108465
final public function delete($path)
    {

        //If we have permission to remove this file
        if ($this->isWritable($path)) {
            if (!@unlink($path)) //This is highly unreliable as unlink returns a warning not a bool
            {
                return false;
            }
        } else {
            if (!@unlink($path)) //This is highly unreliable as unlink returns a warning not a bool
            {
                return false;
            }
        }

        return true;
    }
1113760
public function deleteFolder(String $path) : Bool
    {
        if( @ssh2_sftp_rmdir($this->connect, $path) )
        {
            return true;
        }
        else
        {
            throw new FolderNotFoundException(NULL, $path);
        }

    }
270393
protected function removeEmptyDirs($path)
    {
        $parentDirName = $this->getParentDirName($path);

        $res = true;
        if ($this->isDirEmpty($parentDirName)) {
            $res &= $this->rmdir($parentDirName);
            $res &= $this->removeEmptyDirs($parentDirName);
        }

        return (bool) $res;
    }
278829
public function deleteDirectoryContents($path)
    {
        $dir = new \RecursiveDirectoryIterator($path);
        $iterator = new \RecursiveIteratorIterator($dir, \RecursiveIteratorIterator::CHILD_FIRST);

        /** @var \SplFileInfo $object */
        foreach ($iterator as $object) {
            if (!in_array($object->getBasename(), ['.', '..'])) {
                if ($object->isLink() || $object->isFile()) {
                    unlink($object->getPathname());
                } else if ($object->isDir()) {
                    rmdir($object->getPathname());
                }
            }
        }
    }
1133840
public static function deleteDirectory($path)
    {
        if (!is_dir($path)) {
            return false;
        }

        $files = array_diff(scandir($path), ['.', '..']);
        foreach ($files as $file) {
            $inner_file = static::join($path, $file);
            if (is_dir($inner_file)) {
                // Delete inner directory recursive
                static::deleteDirectory($inner_file);
            } else {
                // Delete file
                unlink($inner_file);
            }
        }

        return rmdir($path);
    }
372111
public function rmdir($path)
    {
        $files = array_diff(scandir($path), array('.', '..'));
        foreach ($files as $file) {
            (is_dir("$path/$file")) ? $this->rmdir("$path/$file") : unlink("$path/$file");
        }
        return rmdir($path);
    }
1158112
public static function remove($path, $deleteDir = true)
    {
        // minimum security check
        if ($path == '' || $path == '/' || $path == DIRECTORY_SEPARATOR) {
            throw new \InvalidArgumentException('The root cannot be removed !!');
        }

        if (!file_exists($path)) {
            return true;
        }

        $dir = new \DirectoryIterator($path);
        foreach ($dir as $dirContent) {
            // file deletion
            if ($dirContent->isFile() || $dirContent->isLink()) {
                unlink($dirContent->getPathName());
            } else {
                // recursive directory deletion
                if (!$dirContent->isDot() && $dirContent->isDir()) {
                    self::remove($dirContent->getPathName());
                }
            }
        }
        unset($dir);
        unset($dirContent);

        // removes the parent directory
        if ($deleteDir) {
            rmdir($path);
        }
    }
296488
public function delete(string $path) : bool
	{
		$path = $this->normalizePath($path);
		
		// Check if the path contains folders we dont want to delete
		if (str_contains($path, $this->folderPathExcludeList)) {
			return true;
		}
		
		$requestUrl = $this->siteUrl.'/sites/'.$this->siteName.'/_api/Web/GetFolderByServerRelativeUrl(\''.$this->folderPath.$path.'\')';
		
		$this->requestHeaders['IF-MATCH'] = 'etag';
			
		$this->requestHeaders['X-HTTP-Method'] = 'DELETE';
				
		$options = [
			'headers' => $this->requestHeaders,
		];
			
		$response = $this->send('POST', $requestUrl, $options);
		
		return $response->getStatusCode() === 200 ? true : false;
	}
1251508
protected function removeDirectory($path)
    {
        $files = glob($path . '/*');
        foreach ($files as $file) {
            if (is_dir($file)) {
                static::removeDirectory($file);
            } else if (basename($file) !== '.gitignore') {
                unlink($file);
            }
        }
        if ($path !== $this->cacheRoot) {
            rmdir($path);
        }

        return;
    }
1083814
public function deleteDir($path)
    {
        if (strpos($path, $this->directoryList->getPath('var')) === false) {
            return sprintf("Failed to delete directory - '%s'", $path);
        }

        $classFunc = [__CLASS__, __FUNCTION__];
        return is_file($path)
            ?
            @unlink($path)
            :
            array_map($classFunc, glob($path . '/*')) == @rmdir($path);
    }
1199044
public function deleteDirectory($path)
    {
        if (false === $this->exists($path)) {
            return $this;
        }

        $this->getFilesystem()->remove($path);

        return $this;
    }
1294852
public function delete($path)
    {
        return (bool)$this->normalizeResponse(
            Cosapi::delFile($this->getBucket(), $path)
        );
    }