API15:JFolder/delete
From Joomla! Documentation
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.
Contents |
Description
Delete a folder.
[<! removed edit link to red link >]
<! removed transcluded page call, red link never existed >
Syntax
delete($path)
| Parameter Name | Default Value | Description |
|---|---|---|
| $path | The path to the folder to delete. |
Returns
boolean True on success.
Defined in
libraries/joomla/filesystem/folder.php
Importing
jimport( 'joomla.filesystem.folder' );
Source Body
function delete($path) { // Sanity check if (!$path) { // Bad programmer! Bad Bad programmer! JError::raiseWarning(500, 'JFolder::delete: ' . JText::_('Attempt to delete base directory') ); return false; } // Initialize variables jimport('joomla.client.helper'); $ftpOptions = JClientHelper::getCredentials('ftp'); // Check to make sure the path valid and clean $path = JPath::clean($path); // Is this really a folder? if (!is_dir($path)) { JError::raiseWarning(21, 'JFolder::delete: ' . JText::_('Path is not a folder'), 'Path: ' . $path); return false; } // Remove all the files in folder if they exist $files = JFolder::files($path, '.', false, true, array()); if (!empty($files)) { jimport('joomla.filesystem.file'); if (JFile::delete($files) !== true) { // JFile::delete throws an error return false; } } // Remove sub-folders of folder $folders = JFolder::folders($path, '.', false, true, array()); foreach ($folders as $folder) { if (is_link($folder)) { // Don't descend into linked directories, just delete the link. jimport('joomla.filesystem.file'); if (JFile::delete($folder) !== true) { // JFile::delete throws an error return false; } } elseif (JFolder::delete($folder) !== true) { // JFolder::delete throws an error return false; } } if ($ftpOptions['enabled'] == 1) { // Connect the FTP client jimport('joomla.client.ftp'); $ftp = &JFTP::getInstance( $ftpOptions['host'], $ftpOptions['port'], null, $ftpOptions['user'], $ftpOptions['pass'] ); } // 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)) { $ret = true; } elseif ($ftpOptions['enabled'] == 1) { // Translate path and delete $path = JPath::clean(str_replace(JPATH_ROOT, $ftpOptions['root'], $path), '/'); // FTP connector throws an error $ret = $ftp->delete($path); } else { JError::raiseWarning( 'SOME_ERROR_CODE', 'JFolder::delete: ' . JText::_('Could not delete folder'), 'Path: ' . $path ); $ret = false; } return $ret; }
[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >
Examples
<CodeExamplesForm />
