Rename directory based only on new name for last element. Example: rename('/var/www/html', 'php') => /var/www/php
@param string $path
@param string $newDirName
@return bool
176151
public static function rename($path, $newDirName)
    {
        $path = Normalize::diskFullPath($path);

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

        $path = rtrim($path, DIRECTORY_SEPARATOR);
        $separatedPath = explode(DIRECTORY_SEPARATOR, $path);
        array_pop($separatedPath);
        $clearPath = implode(DIRECTORY_SEPARATOR, $separatedPath);

        @rename($path, $clearPath . DIRECTORY_SEPARATOR . $newDirName);

        return true;
    }
597377
public function _rename( $srcFilePath, $dstFilePath )
    {
        if ( strcmp( $srcFilePath, $dstFilePath ) == 0 )
            return false;

        // fetch source file metadata
        $metaData = $this->_fetchMetadata( $srcFilePath );
        // if source file does not exist then do nothing.
        // @todo Throw an exception
        if ( !$metaData )
            return false;

        $this->_begin( __METHOD__ );

        $dstFilePathStr  = $this->_quote( $dstFilePath );
        $dstNameTrunkStr = $this->_quote( self::nameTrunk( $dstFilePath, $metaData['scope'] ) );

        // Mark entry for update to lock it
        $sql = "SELECT * FROM " . $this->dbTable( $srcFilePath ) . " WHERE name_hash=" . $this->_md5( $srcFilePath ) . " FOR UPDATE";
        if ( !$this->_query( $sql, "_rename($srcFilePath, $dstFilePath)" ) )
        {
            // @todo Throw an exception
            eZDebug::writeError( "Failed locking file '$srcFilePath'", __METHOD__ );
            $this->_rollback( __METHOD__ );
            return false;
        }

        if ( $this->_exists( $dstFilePath, false, false ) )
            $this->_purge( $dstFilePath, false );

        // Create a new meta-data entry for the new file to make foreign keys happy.
        $sql = "INSERT INTO " . $this->dbTable( $srcFilePath ) . " ".
               "(name, name_trunk, name_hash, datatype, scope, size, mtime, expired) " .
               "SELECT $dstFilePathStr AS name, $dstNameTrunkStr as name_trunk, " . $this->_md5( $dstFilePath ) . " AS name_hash, " .
               "datatype, scope, size, mtime, expired FROM " . $this->dbTable( $srcFilePath ) . " " .
               "WHERE name_hash=" . $this->_md5( $srcFilePath );
        if ( !$this->_query( $sql, "_rename($srcFilePath, $dstFilePath)" ) )
        {
            eZDebug::writeError( "Failed making new file entry '$dstFilePath'", __METHOD__ );
            $this->_rollback( __METHOD__ );
            // @todo Throw an exception
            return false;
        }

        if ( !$this->dfsbackend->copyFromDFSToDFS( $srcFilePath, $dstFilePath ) )
        {
            $this->_fail( "Failed to copy DFS://$srcFilePath to DFS://$dstFilePath" );
        }

        // Remove old entry
        $sql = "DELETE FROM " . $this->dbTable( $srcFilePath ) . " WHERE name_hash=" . $this->_md5( $srcFilePath );
        if ( !$this->_query( $sql, "_rename($srcFilePath, $dstFilePath)" ) )
        {
            eZDebug::writeError( "Failed removing old file '$srcFilePath'", __METHOD__ );
            $this->_rollback( __METHOD__ );
            // @todo Throw an exception
            return false;
        }

        // delete original DFS file
        // @todo Catch an exception
        $this->dfsbackend->delete( $srcFilePath );

        $this->_commit( __METHOD__ );

        return true;
    }
1270229
public function renameOnDFS( $oldPath, $newPath )
    {
        $oldPathHandler = $this->getHandler( $oldPath );
        $newPathHandler = $this->getHandler( $newPath );

        // same handler, normal rename
        if ( $oldPathHandler === $newPathHandler )
        {
            return $oldPathHandler->renameOnDFS( $oldPath, $newPath );
        }
        // different handlers, create on new, delete on old
        else
        {
            if ( $newPathHandler->createFileOnDFS( $newPath, $oldPathHandler->getContents( $oldPath ) ) !== true )
                return false;

            return $oldPathHandler->delete( $oldPath );
        }
    }
1041627
public function newFolder($namefile,$path){
        $fullpath = $this->getFullPath().$path;
        $namefile = $this->clearNameFile($namefile);
        $namefile = $this->sanitizeNameFolder($namefile);
        $dir = new Filesystem;
        if($dir->exists($fullpath.$namefile)){
            $result = array("query"=>"BE_NEW_FOLDER_EXISTED %s","params"=>array($path.$namefile));
            $this->setInfo(array("msg"=>$result,"status"=>0));
            if( $this->config['debug'] ) $this->_log(__METHOD__." - Ya existe: ".$path.$namefile);
            return false;
        }else{
            $dir->mkdir($fullpath.$namefile);
            $result = array("query"=>"BE_NEW_FOLDER_CREATED %s","params"=>array($path.$namefile));
            $this->setInfo(array("msg"=>$result,"data"=>array( "path" => $path, "namefile" => $namefile )));
            return true;
        }
    }
328094
public function rename($nameold,$namenew,$path){
        if($this->validNameFile($nameold,false) && $this->validNameFile($namenew,false)){
            $fullpath = $this->getFullPath().$path;
            $nameold = $this->clearNameFile($nameold);
            $namenew = $this->clearNameFile($namenew);

            $file = new Filesystem;
            if($file->exists($fullpath.$nameold)){
                if( $this->config['debug'] ) $this->_log('$fullpath.$nameold - '.$fullpath.$nameold);
                if(is_dir($fullpath.$nameold)){
                    $namenew = $this->sanitizeNameFolder($namenew);
                    if($file->exists($fullpath.$namenew)==false){
                        $file->rename($fullpath.$nameold,$fullpath.$namenew);
                        $result = array("query"=>"BE_RENAME_MODIFIED","params"=>array());
                        $this->setInfo(array("msg"=>$result,"data"=>array("namefile" => $namenew )));

                    }else{
                        $result = array("query"=>"BE_RENAME_EXISTED","params"=>array());
                        $this->setInfo(array("msg"=>$result,"status"=>0));
                    }
                }elseif(is_file($fullpath.$nameold)){
                    if($this->validExt($nameold)){
                        $extold = $this->getExtension($nameold);
                        $namenew = $namenew.'.'.$extold;
                        if($file->exists($fullpath.$namenew)==false){
                            $file2 = new \SplFileInfo($fullpath.$nameold);
                            if(in_array($file2->getExtension(), $this->config['images']['images_ext'])){
                                $filename = $file2->getFilename();
                                foreach ($this->config['images']['resize'] as $key => $value) {
                                    $image_info = $this->imageSizeName($path,$filename,$value);
                                    $filename_old = $image_info['name'];
                                    $fullpaththumb_name = $this->getFullPath().'/'.$this->config['folder_thumb'].$path.$filename_old;
                                    $file->remove($fullpaththumb_name);
                                }
                            }
                            $file->rename($fullpath.$nameold,$fullpath.$namenew);
                            $file3 = new \SplFileInfo($fullpath.$namenew);
                            $this->createThumb($file3,$path);
                            $result = array("query"=>"BE_RENAME_MODIFIED","params"=>array());
                            $this->setInfo(array("msg"=>$result,"data"=>array("namefile" => $namenew )));
                        }else{
                            $result = array("query"=>"BE_RENAME_EXISTED","params"=>array());
                            $this->setInfo(array("msg"=>$result,"status"=>0));
                        }
                    }else{
                        $result = array("query"=>"BE_RENAME_FILENAME_NOT_VALID","params"=>array());
                        $this->setInfo(array("msg"=>$result, "status"=>0));
                    }
                }
            }else{
                $result = array("query"=>"BE_RENAME_NOT_EXISTS","params"=>array());
                $this->setInfo(array("msg"=>$result, "status"=>0));
            }
        }else{
           $result = array("query"=>"BE_RENAME_FILENAME_NOT_VALID","params"=>array());
           $this->setInfo(array("msg"=>$result, "status"=>0));
       }
   }
84231
public function rename($path, $newpath)
    {
        $statusCopy = $this->copy($path, $newpath);
        $statusRemoveOld = $this->delete($path);

        return $statusCopy && $statusRemoveOld;
    }
1232518
public function rename($oldName, $newName, $pathToFile = null)
    {
        if ($pathToFile==null) {
            $pathToFile=$this->_filePath;
        }
        if (file_exists($pathToFile."/".$oldName)) {
            $this->createDir($pathToFile);
            return rename($pathToFile."/".$oldName, $pathToFile."/".$newName);
        } else {
            return false;
        }
    }
473219
public function rename($path)
    {
        // This implementation supersedes the Flysystem's one. Indeed, while using connectors
        // such as the Amazon S3 (v3) connector, rename on directories does not work. A custom
        // implementation is then needed.
        $contents = $this->getFileSystem()->listContents($this->getPrefix(), true);

        // Filter files only.
        $filePaths = [];
        foreach ($contents as $content) {
            if ($content['type'] === 'file') {
                $filePaths[]= [
                    'source' => $content['path'],
                    'destination' => str_replace($this->getPrefix(), $path, $content['path'])];
            }
        }

        foreach ($filePaths as $renaming) {
            try {
                if ($this->getFileSystem()->rename($renaming['source'], $renaming['destination']) === false) {
                    throw new \common_exception_FileSystemError("Unable to rename '" . $this->getPrefix() . "' into '${path}'.");
                }
            } catch (FileExistsException $e) {
                throw new \common_exception_FileSystemError("Unable to rename '" . $this->getPrefix() . "' into '${path}'. File already exists.");
            }
        }

        if (!$this->deleteSelf()) {
            throw new \common_exception_FileSystemError("Could not finalize renaming of '" . $this->getPrefix() . "' into '${path}'.");
        }

        return true;
    }
181468
public function rename(string $oldName, string $newName)
    {
        if (!@ftp_rename($this->ftp, $oldName, $newName)) {
            throw new Exception(sprintf("Cannot rename file from %s to %s", $oldName, $newName));
        }

        return $this;
    }
790257
public function rename( $new_file )
    {
        $res = @rename( $this->path, $new_file->getPath() );
        if ( $res === FALSE ){
            throw new FileRenameException($this, $new_file);
        }
    }
511044
public function rename($new_name, $new_extension = false)
	{
		$info = pathinfo($this->path);

		$new_name = str_replace(array('..', '/', '\\'), array('', '', ''), $new_name);
		$extension = $new_extension === false
			? $info['extension']
			: ltrim($new_extension, '.');
		$extension = ! empty($extension) ? '.'.$extension : '';

		$new_path = $info['dirname'].DS.$new_name.$extension;

		$return =  $this->area->rename($this->path, $new_path);
		$return and $this->path = $new_path;

		return $return;
	}
1105376
public function rename($oldPath, $newPath)
    {
        $payload = $this->getNewFileLocationPayload($newPath);

        return $this->updateMetadata($oldPath, $payload);
    }
999981
public static function rename($path, $newpath, $cb = null, $pri = EIO_PRI_DEFAULT)
    {
        $cb = CallbackWrapper::forceWrap($cb);
        if (!self::$supported) {
            $r = rename($path, $newpath);
            if ($cb) {
                $cb($path, $newpath, $r);
            }
            return $r;
        }
        return eio_rename($path, $newpath, $pri, $cb, $path);
    }
1224902
function RenameFile($type, $dir, $filename, $newname)
    {
        $dir = $this->AccessDir($dir, $type);
        if (!$dir)
        {
            return false;
        }

        $filename = trim($filename);

        if (empty($filename))
        {
            return 'error';
        }

        if (!is_dir($dir . '/.thumbs'))
        {
            return 'error';
        }

        $dbfile = $dir . '/.thumbs/.db';
        if (is_file($dbfile))
        {
            $dbfilehandle = fopen($dbfile, "r");
            $dblength = filesize($dbfile);
            if ($dblength > 0)
            {
                $dbdata = fread($dbfilehandle, $dblength);
            }
            else
            {
                $dbdata = '';
            }
            fclose($dbfilehandle);
        }
        else
        {
            return 'error';
        }

        $files = unserialize($dbdata);

        foreach ($files as $file => $fdata)
        {
            if ($file == $filename)
            {
                $files[$file]['general']['name'] = $newname;
                break;
            }
        }

        $dbfilehandle = fopen($dbfile, "w");
        fwrite($dbfilehandle, serialize($files));
        fclose($dbfilehandle);

        return 'ok';
    }
832161
public function rename($path, $newPath)
    {
        $this->recursiveCreateDir(Util::dirname($newPath));

        $location = $this->applyPathPrefix($path);
        $destination = $this->applyPathPrefix($newPath);

        try {
            $this->share->rename($location, $destination);
        } catch (NotFoundException $e) {
            return false;
        } catch (AlreadyExistsException $e) {
            return false;
        }

        return true;
    }
391779
public function rename($path, $newpath)
    {
        $pathinfo = pathinfo($path);
        if ($pathinfo['dirname'] != '.') {
            $path_remote = $pathinfo['dirname'] . '/' . $pathinfo['filename'];
        } else {
            $path_remote = $pathinfo['filename'];
        }

        $newpathinfo = pathinfo($newpath);
        if ($newpathinfo['dirname'] != '.') {
            $newpath_remote = $newpathinfo['dirname'] . '/' . $newpathinfo['filename'];
        } else {
            $newpath_remote = $newpathinfo['filename'];
        }

        $result = Uploader::rename($path_remote, $newpath_remote);

        return $result['public_id'] == $newpathinfo['filename'];
    }
1222591
public function rename($newpath)
    {
        if ($this->filesystem->rename($this->path, $newpath)) {
            $this->path = $newpath;

            return true;
        }

        return false;
    }