Remove folder (with subfolders) from the server

@param string $folder Folder name

@return boolean True on success, False on failure
189862
function delete_folder($folder)
    {
        if (!$this->check_connection()) {
            return false;
        }

        $delm = $this->get_hierarchy_delimiter();

        // get list of sub-folders or all folders
        // if folder name contains special characters
        $path       = strspn($folder, '%*') > 0 ? ($folder . $delm) : '';
        $sub_mboxes = $this->list_folders('', $path . '*');

        // According to RFC3501 deleting a \Noselect folder
        // with subfolders may fail. To workaround this we delete
        // subfolders first (in reverse order) (#5466)
        if (!empty($sub_mboxes)) {
            foreach (array_reverse($sub_mboxes) as $mbox) {
                if (strpos($mbox, $folder . $delm) === 0) {
                    if ($this->conn->deleteFolder($mbox)) {
                        $this->conn->unsubscribe($mbox);
                        $this->clear_message_cache($mbox);
                    }
                }
            }
        }

        // delete the folder
        if ($result = $this->conn->deleteFolder($folder)) {
            // and unsubscribe it
            $this->conn->unsubscribe($folder);
            $this->clear_message_cache($folder);
        }

        $this->clear_cache('mailboxes', true);

        return $result;
    }
32627
public function removeAdditionalFolderAction()
    {
        // Check current user authorization
        if (null !== $response = $this->checkAuth($this->resourceCode, array(), AccessManager::UPDATE)) {
            return $response;
        }

        $folder_id = \intval($this->getRequest()->request->get('additional_folder_id'));

        if ($folder_id > 0) {
            $event = new ContentRemoveFolderEvent(
                $this->getExistingObject(),
                $folder_id
            );

            try {
                $this->dispatch(TheliaEvents::CONTENT_REMOVE_FOLDER, $event);
            } catch (\Exception $e) {
                return $this->errorPage($e);
            }
        }

        return $this->redirectToEditionTemplate();
    }
1220022
public static function remove(string $link = ''): bool
    {
        $link = static::normalizePath($link);
        if (static::exists($link)) {
            return @\unlink($link);
        }
        return false;
    }
937009
public function trashPurgeFolderAction(Folder $folder)
    {
        $this->get('cms.folder')->remove($folder);

        $this->addFlash('success', 'Папка удалена.');

        return $this->redirectToRoute('cms_admin_structure_trash');
    }
1159193
public function clean($folder, $removeDirectory = false)
    {
        if ( ! is_dir($folder)) {
            throw new \Exception(('Not a folder.'));
        }

        array_map('unlink', glob($folder . DIRECTORY_SEPARATOR . '*'));
        if ($removeDirectory && file_exists($folder)) {
            rmdir($folder);
        }
    }
83318
public function rename_folder($folder, $new_name)
    {
        if (!strlen($new_name)) {
            return false;
        }

        if (!$this->check_connection()) {
            return false;
        }

        $delm = $this->get_hierarchy_delimiter();

        // get list of subscribed folders
        if ((strpos($folder, '%') === false) && (strpos($folder, '*') === false)) {
            $a_subscribed = $this->list_folders_subscribed('', $folder . $delm . '*');
            $subscribed   = $this->folder_exists($folder, true);
        }
        else {
            $a_subscribed = $this->list_folders_subscribed();
            $subscribed   = in_array($folder, $a_subscribed);
        }

        $result = $this->conn->renameFolder($folder, $new_name);

        if ($result) {
            // unsubscribe the old folder, subscribe the new one
            if ($subscribed) {
                $this->conn->unsubscribe($folder);
                $this->conn->subscribe($new_name);
            }

            // check if folder children are subscribed
            foreach ($a_subscribed as $c_subscribed) {
                if (strpos($c_subscribed, $folder.$delm) === 0) {
                    $this->conn->unsubscribe($c_subscribed);
                    $this->conn->subscribe(preg_replace('/^'.preg_quote($folder, '/').'/',
                        $new_name, $c_subscribed));

                    // clear cache
                    $this->clear_message_cache($c_subscribed);
                }
            }

            // clear cache
            $this->clear_message_cache($folder);
            $this->clear_cache('mailboxes', true);
        }

        return $result;
    }
63284
public static function remove($path)
    {
        $path = Normalize::diskFullPath($path);

        if (!self::exist($path)) {
            return false;
        }

        foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST) as $dir) {
            $dir->isFile() ? @unlink($dir->getPathname()) : @rmdir($dir->getPathname());
        }
        return @rmdir($path);
    }
404535
public function moveFolder($currentFolder, $newFolder)
    {
        if ($newFolder == $currentFolder) {
            $this->errors[] = 'Please select another folder to move this folder into.';

            return false;
        }

        if (starts_with($newFolder, $currentFolder)) {
            $this->errors[] = 'You can not move this folder inside of itself.';

            return false;
        }

        return $this->disk->getDriver()->rename($currentFolder, $newFolder);
    }
81731
protected function folderContainsValidGithubRepo($folder)
    {
        $remote = $this->remoteGithub($folder);
        if ($this->isAGithubRepo($remote)) {
            return true;
        }
        return false;
    }
606334
private function removeFolderInFileSystem(Folder $folder)
	{
		$folderPath = $folder->getPath(DIRECTORY_SEPARATOR, true);

		$folderExternalPath = $this->getExternalPath() . $folderPath;
		$folderInternalPath = $this->getInternalPath() . $folderPath;

		//remove empty _size folders (or whatever the prefix is); we expect these folders to be empty
		foreach (array($folderExternalPath, $folderInternalPath) as $path) {
			$sizeBase = $path . DIRECTORY_SEPARATOR . self::RESERVED_DIR_SIZE;
			if (is_dir($sizeBase)) {
				foreach (glob($sizeBase . DIRECTORY_SEPARATOR . '*') as $subSize) {
					@rmdir($subSize);
				}
				@rmdir($sizeBase);
			}
		}

		// we are ignoring that one of the folders might not exist
		$resultInternal = @rmdir($folderInternalPath);
		$resultExternal = @rmdir($folderExternalPath);
	}
1220044
public static function deleteFiles($dir) {
		$dir = self::normalizePath($dir);
		if (\is_dir($dir)) {
			$files = \scandir($dir);
			foreach ($files as $file) {
				$fullPath = self::normalizePath(self::combinePath($dir, $file));
				if ($file != "." && $file != "..") {
					if (\is_dir($fullPath))
						self::deleteFiles($fullPath);
					else
						@\unlink($fullPath);
				}
			}
			@\rmdir($dir);
		}
		return true;
    }
1141642
public function isDir($folder)
    {
        $metadata = $this->dropbox->getMetadata($this->pathRoot.$folder);
        return is_array($metadata) && isset($metadata['is_dir']) && $metadata['is_dir']==true;
    }
1315175
public function createFolder($folder)
    {
        $folder = trim($folder, "/") . "/";

        if ($folder === "/") {
            return true;
        }

        // Fail if this pseudo directory key already exists
        if ($this->exists($folder)) {
            return true;
        }

        $response = $this->clientS3->putObject(array(
            'Bucket' => $this->bucket,
            'Key'    => $folder,
            'ACL'    => static::ACL_PUBLIC_READ,
            'Body'   => "",
        ));

        return (bool) $response;
    }
1102886
protected function realpath($folder)
    {
        $separator = (string) DIRECTORY_SEPARATOR;

        $search = array('\\', '/', (string) '\\\\');

        $path = str_replace($search, $separator, $folder);

        file_exists($path) || mkdir((string) $path);

        $exists = in_array(substr($path, -1), $search);

        return $exists ? $path : $path . $separator;
    }
569118
public function delete_message($uids, $folder='')
    {
        if (!strlen($folder)) {
            $folder = $this->folder;
        }

        list($uids, $all_mode) = $this->parse_uids($uids);

        // exit if no message uids are specified
        if (empty($uids)) {
            return false;
        }

        if (!$this->check_connection()) {
            return false;
        }

        $deleted = $this->conn->flag($folder, $uids, 'DELETED');

        if ($deleted) {
            // send expunge command in order to have the deleted message
            // really deleted from the folder
            $this->expunge_message($uids, $folder, false);
            $this->clear_messagecount($folder);

            // unset threads internal cache
            unset($this->icache['threads']);

            $this->set_search_dirty($folder);

            // remove message ids from search set
            if ($this->search_set && $folder == $this->folder) {
                // threads are too complicated to just remove messages from set
                if ($this->search_threads || $all_mode) {
                    $this->refresh_search();
                }
                else if (!$this->search_set->incomplete) {
                    $this->search_set->filter(explode(',', $uids));
                }
            }

            // remove cached messages
            $this->clear_message_cache($folder, $all_mode ? null : explode(',', $uids));
        }

        return $deleted;
    }
228374
public function removeCache()
	{
		if ( ! $this->useCache || ! $this->cacheLocation ) return false;

		if ( ! is_dir( $this->cacheLocation ) ) return false;

		$rmrf = function ($dir) use ( &$rmrf )
		{
		    foreach ( glob( $dir ) as $file )
		    {
		        if ( is_dir( $file ) )
		        {
		            $rmrf( "$file/*" );
		            rmdir( $file );
		        }
		        else
		        {
		            unlink( $file );
		        }
		    }
		};

		$rmrf( $this->cacheLocation );

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

    }