FileSys::Rename( FileSys *, Error * )

Rename the file specified by the path protected FileSys member to the file specified by the target FileSys object.

Virtual?

Yes

 

Class

FileSys

 

Arguments

FileSys *target

name of target for rename

 

Error *error

returned error status

Returns

void

 

Notes

On some operating systems, an unlink might be required before calling Rename().

Your implementation must correctly report any system errors that may occur during the rename.

Example

To use Rename() to rename /usr/logs/log2 to /usr/logs/log1:

FileSys *f1 = FileSys::Create( FST_TEXT );
FileSys *f2 = FileSys::Create( FST_TEXT );
Error e;

f1->Set( "/usr/logs/log1" );
f2->Set( "/usr/logs/log2" );

f1->Rename( f2, &e );

To reimplement Rename() to report errors with Error::Sys() and provide debugging output:

void FileSysDemo::Rename( FileSys *target, Error *e )
{
    if ( rename( Name(), target->Name() ) < 0 )
        e->Sys( "rename", Name() );

    if ( DEBUG )
        printf( "Debug (Rename): %s to %s\n", Name(), target->Name() );
}