/**
  * Previously in \TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::folder_move()
  *
  * @param Folder $folderObject
  * @param string $newName
  * @throws \Exception
  * @throws \InvalidArgumentException
  * @return Folder
  */
 public function renameFolder($folderObject, $newName)
 {
     // Renaming the folder should check if the parent folder is writable
     // We cannot do this however because we cannot extract the parent folder from a folder currently
     if (!$this->checkFolderActionPermission('rename', $folderObject)) {
         throw new Exception\InsufficientUserPermissionsException('You are not allowed to rename the folder "' . $folderObject->getIdentifier() . '\'', 1357811441);
     }
     $sanitizedNewName = $this->driver->sanitizeFileName($newName);
     $returnObject = null;
     if ($this->driver->folderExistsInFolder($sanitizedNewName, $folderObject->getIdentifier())) {
         throw new \InvalidArgumentException('The folder ' . $sanitizedNewName . ' already exists in folder ' . $folderObject->getIdentifier(), 1325418870);
     }
     $this->emitPreFolderRenameSignal($folderObject, $sanitizedNewName);
     $fileObjects = $this->getAllFileObjectsInFolder($folderObject);
     $fileMappings = $this->driver->renameFolder($folderObject->getIdentifier(), $sanitizedNewName);
     // Update the identifier of all file objects
     foreach ($fileObjects as $oldIdentifier => $fileObject) {
         $newIdentifier = $fileMappings[$oldIdentifier];
         $fileObject->updateProperties(array('identifier' => $newIdentifier));
         $this->getIndexer()->updateIndexEntry($fileObject);
     }
     $returnObject = $this->getFolder($fileMappings[$folderObject->getIdentifier()]);
     $this->emitPostFolderRenameSignal($folderObject, $returnObject->getName());
     return $returnObject;
 }