cwFile.h/cpp : backup() now takes an optional destination directory.
This commit is contained in:
parent
376684e3b5
commit
1ea10e6d7f
@ -463,7 +463,7 @@ cw::rc_t cw::file::copy(
|
||||
|
||||
}
|
||||
|
||||
cw::rc_t cw::file::backup( const char* dir, const char* name, const char* ext )
|
||||
cw::rc_t cw::file::backup( const char* dir, const char* name, const char* ext, const char* dst_dir )
|
||||
{
|
||||
rc_t rc = kOkRC;
|
||||
char* newName = nullptr;
|
||||
@ -490,6 +490,9 @@ cw::rc_t cw::file::backup( const char* dir, const char* name, const char* ext )
|
||||
goto errLabel;
|
||||
}
|
||||
|
||||
if( dst_dir == nullptr )
|
||||
dst_dir = pp->dirStr;
|
||||
|
||||
// iterate until a unique file name is found
|
||||
for(n=0; 1; ++n)
|
||||
{
|
||||
@ -499,7 +502,7 @@ cw::rc_t cw::file::backup( const char* dir, const char* name, const char* ext )
|
||||
newName = mem::printf(newName,"%s_%i",pp->fnStr,n);
|
||||
|
||||
// form the new file name into a complete path
|
||||
if((newFn = filesys::makeFn(pp->dirStr,newName,pp->extStr,nullptr)) == nullptr )
|
||||
if((newFn = filesys::makeFn(dst_dir,newName,pp->extStr,nullptr)) == nullptr )
|
||||
{
|
||||
rc = cwLogError(kOpFailRC,"A backup file name could not be formed for the file '%s'.",cwStringNullGuard(newName));
|
||||
goto errLabel;
|
||||
|
2
cwFile.h
2
cwFile.h
@ -112,7 +112,7 @@ namespace cw
|
||||
// The integers chosen with zero and are incremented until an
|
||||
// unused file name is found in the same directory as 'fn'.
|
||||
// If the file identified by 'fn' is not found then the function returns quietly.
|
||||
rc_t backup( const char* dir, const char* name, const char* ext );
|
||||
rc_t backup( const char* dir, const char* name, const char* ext, const char* dst_dir=nullptr );
|
||||
|
||||
// Allocate and fill a zero terminated string from a file.
|
||||
// Set *bufByteCntPtr to count of bytes read into the buffer.=
|
||||
|
Loading…
Reference in New Issue
Block a user