Move a single file from the source filepath to the target filepath. This is functionally similar to the UNIX mv command or the C library function rename except that overwriting a file is not permitted.
| Return Type | Function name | Arguments |
|---|---|---|
| hzEcode | Filemove | (hzString&,hzString&,) |
Declared in file: hzDirectory.h
Defined in file : hzDirectory.cpp
Function Logic:
Function body:
hzEcode Filemove (hzString& src)hzString& tgt,
{
// Category: Directory
//
// Move a single file from the source filepath to the target filepath. This is functionally similar to the UNIX mv command or the C library function rename
// except that overwriting a file is not permitted.
//
// Arguments: 1) source The source filepath
// 2) target The target filepath
//
// Returns: E_ARGUMENT If either the source or the target is not supplied
// E_NOTFOUND If the source file does not exist
// E_DUPLICATE If the target file does exist
// E_TYPE If either the source or target is a directory
// E_WRITEFAIL If the rename operation failed
// E_OK If the file was moved
_hzfunc(__func__) ;
FSTAT fs ; // File status
if (!tgt || !src)
return E_ARGUMENT ;
if (lstat(src, &fs) < 0)
return E_NOTFOUND ;
if (S_ISDIR(fs.st_mode))
return E_TYPE ;
// Check if target exists
if (lstat(tgt, &fs) == 0)
{
if (S_ISDIR(fs.st_mode))
return E_TYPE ;
return E_DUPLICATE ;
}
if (rename(*src, *tgt) < 0)
return E_WRITEFAIL ;
return E_OK ;
}