public function renameFolder(Request $request)
    {
        $namespace = $request->request->get('namespace');
        $parent = $request->request->get('parent');
        $oldName = $request->request->get('oldname');
        $newName = $request->request->get('newname');

        try {
            $dir = $this->filesystem()->getDir("$namespace://$parent/$oldName");
            if (!$dir) {
                return $this->json(
                    sprintf("Only directories are allowed to be renamed with this method"),
                    Response::HTTP_BAD_REQUEST
                );
            }
            $this->filesystem()->rename("$namespace://$parent/$oldName", "$parent/$newName");

            return $this->json($newName, Response::HTTP_OK);
        } catch (ExceptionInterface $e) {
            $msg = Trans::__('Unable to rename directory: %DIR%', ['%DIR%' => $oldName]);
            $this->logException($msg, $e);

            if ($e instanceof FileExistsException) {
                $status = Response::HTTP_CONFLICT;
            } elseif ($e instanceof FileNotFoundException) {
                $status = Response::HTTP_NOT_FOUND;
            } else {
                $status = Response::HTTP_INTERNAL_SERVER_ERROR;
            }

            return $this->json($msg, $status);
        }
    }
public function renameFolder(Request $request)
    {
        $namespace = $request->request->get('namespace');
        $parent = $request->request->get('parent');
        $oldName = $request->request->get('oldname');
        $newName = $request->request->get('newname');

        try {
            $dir = $this->filesystem()->getDir("$namespace://$parent/$oldName");
            if (!$dir) {
                return $this->json(
                    sprintf("Only directories are allowed to be renamed with this method"),
                    Response::HTTP_BAD_REQUEST
                );
            }
            $this->filesystem()->rename("$namespace://$parent/$oldName", "$parent/$newName");

            return $this->json($newName, Response::HTTP_OK);
        } catch (ExceptionInterface $e) {
            $msg = Trans::__('Unable to rename directory: %DIR%', ['%DIR%' => $oldName]);
            $this->logException($msg, $e);

            if ($e instanceof FileExistsException) {
                $status = Response::HTTP_CONFLICT;
            } elseif ($e instanceof FileNotFoundException) {
                $status = Response::HTTP_NOT_FOUND;
            } else {
                $status = Response::HTTP_INTERNAL_SERVER_ERROR;
            }

            return $this->json($msg, $status);
        }
    }
public function renameFolder ( Request $ request ) { $ namespace = $ request -> request -> get ( 'namespace' ) ; $ parent = $ request -> request -> get ( 'parent' ) ; $ oldName = $ request -> request -> get ( 'oldname' ) ; $ newName = $ request -> request -> get ( 'newname' ) ; try { $ dir = $ this -> filesystem ( ) -> getDir ( "$namespace://$parent/$oldName" ) ; if ( ! $ dir ) { return $ this -> json ( sprintf ( "Only directories are allowed to be renamed with this method" ) , Response :: HTTP_BAD_REQUEST ) ; } $ this -> filesystem ( ) -> rename ( "$namespace://$parent/$oldName" , "$parent/$newName" ) ; return $ this -> json ( $ newName , Response :: HTTP_OK ) ; } catch ( ExceptionInterface $ e ) { $ msg = Trans :: __ ( 'Unable to rename directory: %DIR%' , [ '%DIR%' => $ oldName ] ) ; $ this -> logException ( $ msg , $ e ) ; if ( $ e instanceof FileExistsException ) { $ status = Response :: HTTP_CONFLICT ; } elseif ( $ e instanceof FileNotFoundException ) { $ status = Response :: HTTP_NOT_FOUND ; } else { $ status = Response :: HTTP_INTERNAL_SERVER_ERROR ; } return $ this -> json ( $ msg , $ status ) ; } }
Rename a folder within the files directory tree.

@param Request $request

@return \Symfony\Component\HttpFoundation\JsonResponse
Rename a folder within the files directory tree .