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;
    }
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;
    }
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 ; }
Recursively Remove directories if the system allows.

@param string|null $path Path of directory to delete
@return bool Success
Recursively Remove directories if the system allows .