Delete files and folder recursively

@param string $path path of file/folder
493295
public static function recursiveDelete($path) {
		if(is_file($path)) {
			@unlink($path);

		} else {
			$it = new RecursiveIteratorIterator(
				new RecursiveDirectoryIterator($path),
				RecursiveIteratorIterator::CHILD_FIRST
			);

			foreach ($it as $file) {
				if (in_array($file->getBasename(), array('.', '..'))) {
					continue;
				}elseif ($file->isDir()) {
					rmdir($file->getPathname());
				}elseif ($file->isFile() || $file->isLink()) {
					unlink($file->getPathname());
				}
			}
			rmdir($path);
		}

		return false;
	}
95784
public static function delete($path)
    {
        @set_time_limit(ini_get('max_execution_time'));
    
        // Sanity check
        if (!rtrim($path, '/\\'))
        {
            // Bad programmer! Bad Bad programmer!
            throw new \Exception(__METHOD__ . ': You can not delete a base directory.');
        }
    
        // Check to make sure the path valid and clean
        $path = FileHelper::cleanPath($path);
    
        // Is this really a folder?
        if (!is_dir($path))
        {
            throw new \UnexpectedValueException(sprintf('%1$s: Path is not a folder. Path: %2$s', __METHOD__, $path));
        }
    
        // Remove all the files in folder if they exist; disable all filtering
        $files = FileHelper::files($path, true, true);
    
        if (!empty($files)) {
            File::delete($files);
        }
    
        // Remove sub-folders of folder; disable all filtering
        $folders = FileHelper::dirs($path, false, true);
        
        foreach ($folders as $folder) 
        {
            if (is_link($folder))
            {
                // Don't descend into linked directories, just delete the link.
                File::delete($folder);
            }
            else
            {
                static::delete($folder);
            }
        }
    
        // In case of restricted permissions we zap it one way or the other
        // as long as the owner is either the webserver or the ftp.
        if (@rmdir($path))
        {
            return true;
        }
        else
        {
            throw new \Exception(sprintf('%1$s: Could not delete folder. Path: %2$s', __METHOD__, $path));
        }
    }
122508
private function _delete_dir($path = '')
    {
        $cache_path = $this->config->get('cache_path');

        // make sure nobody can delete above the cache root
        if (strpos($path, $cache_path) === false) return;

        if (is_file($path)) {
            return (bool) unlink($path);
        } elseif (is_dir($path)) {
            $scan = glob(rtrim($path,'/').'/*');

            foreach ($scan as $item) {
                $this->_delete_dir($item);
            }

            return rmdir($path);
        }
    }
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;
    }
417408
public function deleteFile($path)
    {
        $path = $this->cleanFolder($path);

        if ($this->checkFileExists($path)) {
            return $this->disk->delete($path);
        }

        return 'File does not exist.';
    }
932197
public static function deleteDir($path)
    {
        if (!is_dir($path)) return;

        $path = rtrim($path, '/') . '/';

        $dir_obj = opendir($path);

        while ($dir = readdir($dir_obj)) {
            if ($dir != '.' && $dir != '..') {
                $file = $path . $dir;
                if (is_dir($file)) {
                    self::deleteDir($file);
                } elseif (is_file($file)) {
                    unlink($file);
                }

            }
        }
        closedir($dir_obj);
        rmdir($path);
    }
1058739
public static function delete($path, $recursive = false)
    {
        Path::validatePath($path);

        if ($recursive) {
            Path::purge($path);
        }

        if (@rmdir($path)) {
            return;
        }

        throw new IOException(sprintf("Cannot delete path %s.", $path));
    }
1322698
public function delete($path)
  {
    if (is_link($path)) {
      $this->_deleteSymlink($path);
    } elseif (is_file($path)) {
      unlink($path);
    } else {
      $iteratorRd = new RecursiveDirectoryIterator($path);
      $iteratorRi = new RecursiveIteratorIterator(
        $iteratorRd, RecursiveIteratorIterator::CHILD_FIRST
      );
      foreach ($iteratorRi as $file) {
        /* @var $file \SplFileInfo */
        $filename = $file->getPathname();
        if ($file->isLink()) {
          $this->_deleteSymlink($filename);
        } elseif ($file->isDir()) {
          if (substr($filename, -1, 1) != ".") {
            rmdir($filename);
          }
        } else {
          unlink($filename);
        }
      }
      rmdir($path);
    }
  }
793742
public function rmdir( $path )
	{
		try {
			$this->fs->deleteDirectory( $path );
		} catch( \Exception $e ) {
			throw new Exception( $e->getMessage(), 0, $e );
		}
	}
981173
public function delete($path): bool
    {
        $result = false;
        $parts = $this->split($path);

        $name = array_shift($parts);
        if (!count($parts)) {
            if (isset($this->ownData[$name])) {
                unset($this->ownData[$name]);
                $result = true;
            }
        } elseif (isset($this->subTrees[$name])) {
            $subtree = $this->subTrees[$name];
            $result = $subtree->delete($parts);
            if ($result && !$subtree->count()) {
                unset($this->subTrees[$name]);
            }
        }

        return $result;
    }
504319
public function delete($path=null)
	{
		if (is_null($path)) return;

		$basePath = $this->getImageBasePath();
		$imagePath = $basePath.'/'.$path;

		if (File::exists($imagePath)) {
			File::delete($imagePath);
		}
	}
1116315
public static function removeDir($path)
    {
        if (is_file($path)) {
            unlink($path);
        } else {
            foreach (scandir($path) as $dir) {
                if ($dir === '.' || $dir === '..') {
                    continue;
                }

                static::removeDir($path.'/'.$dir);
            }

            rmdir($path);
        }
    }
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);
    }
172063
protected function clear($path)
    {
        $directory = new \RecursiveDirectoryIterator($path, 4096);

        $iterator = new \RecursiveIteratorIterator($directory, 2);

        foreach ($iterator as $file) {
            $git = strpos($file->getRealPath(), '.git') !== false;

            $path = (string) $file->getRealPath();

            $git || ($file->isDir() ? rmdir($path) : unlink($path));
        }
    }
214100
public function delete($path)
    {
        $object = $this->applyPathPrefix($path);

        try {
            $this->client->deleteObject($this->bucket, $object);
        } catch (OssException $e) {
            return false;
        }

        return true;
    }
665452
private function deleteFiles($dirPath)
    {
        foreach (glob($dirPath.DIRECTORY_SEPARATOR.'{*,.[!.]*,..?*}', GLOB_BRACE) as $content) {
            if (is_dir($content)) {
                $this->deleteFiles($content);
            } else {
                unlink($content);
            }
        }
        rmdir($dirPath);
    }
259817
public function removePath($path)
	{
		$path = rtrim($path, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
		$this->finder->removePath($path);

		if ($this->environment)
		{
			$this->finder->removePath($path.$this->environment);
		}
	}