Remove dir
@param bool $withFoler
@return $this
13841
public function removeDir($withFolder = false)
    {
        if (!is_dir($this->dir)) {
            return $this;
        }

        foreach (glob($this->dir.'/*') as $item) {
            if (is_dir($item)) {
                static::create($item)->removeDir(true);
            } else {
                @unlink($item);
            }
        }
        if ($withFolder) {
            @rmdir($this->dir);
        }

        return $this;
    }
508899
public static function remove($removeList = array())
    {
        if (!is_array($removeList)) {
            $removeList = array($removeList);
        }
        foreach ($removeList as $value) {
            if (!empty($value)) {
                if (is_dir($value)) {
                    self::deleteDirectory($value);
                }
                if (is_file($value)) {
                    unlink($value);
                }
            }
        }
        return true;
    }
154206
public function removeImage($location = self::IMAGE_HEADER_LEFT) {
    	if (isset($this->_headerFooterImages[$location])) {
    		unset($this->_headerFooterImages[$location]);
    	}
    	return $this;
    }
328433
function remove()
    {
        $path = $this->path();
        if ( file_exists( $path ) )
        {
            eZDir::recursiveDelete( $path );
        }
        $this->setInstalled( false );
    }
582924
protected function rmdir($dir) {
        $iterator = new RecursiveIteratorIterator(
            new RecursiveDirectoryIterator($dir),
            RecursiveIteratorIterator::CHILD_FIRST
        );

        foreach ($iterator as $file) {
            $name = $file->getPathname();

            if (substr($name, -1) === '.') {
                continue;
            }

            if ($file->isDir()) {
                // Remove dir
                rmdir($name);
            } else {
                // Remove file
                unlink($name);
            }
        }

        // Remove the directory itself
        rmdir($dir);
    }
741230
public function excludeFilesFrom($excludeFilesAndDirectories): self
    {
        $this->excludeFilesAndDirectories = $this->excludeFilesAndDirectories->merge($this->sanitize($excludeFilesAndDirectories));

        return $this;
    }
703790
static function clear_dir($dir, $delete_me = false)
    {
        $dir = self::makeVirtualDir($dir, false);
        $result = false;
        if (is_file($dir)){
            $result = @unlink($dir);
        }else
        if (is_dir($dir)){
            $scan = glob(rtrim($dir, '/').'/*');
            foreach ($scan as $path){
                self::clear_dir($path, true);
            }
            $result = $delete_me?@rmdir($dir):true;
        }
        self::deleteVirtualDir($dir);
        return $result;
    }
440964
public function deleteSubtree($withSelf = false, $forceDelete = false)
    {
        $action = ($forceDelete === true ? 'forceDelete' : 'delete');

        $ids = $this->joinClosureBy('descendant', $withSelf)->pluck($this->getKeyName());

        if ($forceDelete) {
            $this->closure->whereIn($this->closure->getDescendantColumn(), $ids)->delete();
        }

        $this->whereIn($this->getKeyName(), $ids)->$action();
    }
537313
static function delete_empty_dir($dir)
    {
        $dir = self::makeVirtualDir($dir, false);
        if (is_dir($dir) && sizeof(scandir($dir)) == 2){
            return @rmdir($dir);
        }
        self::deleteVirtualDir($dir);
        return false;
    }
296806
protected function deleteDirectory($dir)
    {
        $files = new RecursiveIteratorIterator(
            new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS),
            RecursiveIteratorIterator::CHILD_FIRST
        );

        foreach ($files as $fileInfo) {
            $todo = ($fileInfo->isDir() ? 'rmdir' : 'unlink');

            $todo($fileInfo->getRealPath());
        }

        rmdir($dir);
    }
680451
public function removeFile($filePaths, $dirPath = null)
    {
        if (!is_array($filePaths)) {
            $filePaths = (array) $filePaths;
        }

        $result = true;
        foreach ($filePaths as $filePath) {
            if (isset($dirPath)) {
                $filePath = Utils\Util::concatPath($dirPath, $filePath);
            }

            if (file_exists($filePath) && is_file($filePath)) {
                if (function_exists('opcache_invalidate')) {
                    @opcache_invalidate($filePath, true);
                }
                $result &= unlink($filePath);
            }
        }

        return $result;
    }
850404
protected function removeDir(\SplFileInfo $dir, $alsoRemoveFiles = true)
    {

        // clean up the directory
        $this->getService()->cleanUpDir($dir, $alsoRemoveFiles);

        // check if the directory exists, if not return immediately
        if ($dir->isDir() === false) {
            return;
        }

        // delete the directory itself if empty
        @rmdir($dir->getPathname());
    }
954720
public static function removeDirectory(string $dir, bool $remove = true): void
    {
        if (\is_dir($dir)) {
            $entries = \glob($dir . \DIRECTORY_SEPARATOR . '*', \GLOB_NOSORT);
            
            if (empty($entries)) {
                $entries = [];
            }
            
            foreach ($entries as $tmp) {
                if (\is_dir($tmp)) {
                    self::removeDirectory($tmp);
                } else {
                    if (!@\unlink($tmp)) {
                        throw new \RuntimeException(\sprintf('Could not remove directory "%s" due to failed removal of file "%s"%s', $dir, $tmp, self::getErrorInfo()));
                    }
                }
            }
            
            if ($remove) {
                if (!@\rmdir($dir)) {
                    throw new \RuntimeException(sprintf('Could not remove directory "%s"%s', $dir, self::getErrorInfo(error_get_last())));
                }
            }
        }
        
        \clearstatcache(true);
    }
223186
public function useFileDriver(string $dir): self
    {
        $this->setDriver(new \BearFramework\App\FileDataDriver($dir));
        return $this;
    }
1231193
public function delete() {
    if ($this->exists()) {
      
      foreach ($this->getContents() as $item) {
        if (is_object($item) && ($item instanceof File || $item instanceof Dir)) {
          $item->delete(); // rekursiver aufruf für Dir
        }
      }
      
      @rmdir((string) $this); // selbst löschen
    }

    return $this;
  }
924227
public static function cleanUpDir(\SplFileInfo $dir, $alsoRemoveFiles = true)
    {

        // first check if the directory exists, if not return immediately
        if ($dir->isDir() === false) {
            return;
        }

        // remove old archive from webapps folder recursively
        $files = new \RecursiveIteratorIterator(
            new \RecursiveDirectoryIterator($dir->getPathname()),
            \RecursiveIteratorIterator::CHILD_FIRST
        );

        foreach ($files as $file) {
            // skip . and .. dirs
            if ($file->getFilename() === '.' || $file->getFilename() === '..') {
                continue;
            }
            if ($file->isDir()) {
                @rmdir($file->getRealPath());
            } elseif ($file->isFile() && $alsoRemoveFiles) {
                unlink($file->getRealPath());
            } else {
                // do nothing, because file should NOT be deleted obviously
            }
        }
    }
608529
public function removeDirectory($directory)
    {
        $result = @ftp_rmdir($this->connection, $directory);
        
        if ($result === false) {
            throw new Exception('Unable to remove directory');
        }

        return $this;
    }