Logo Search packages:      
Sourcecode: pwlib version File versions  Download package

BOOL PFile::Rename ( const PFilePath oldname,
const PString newname,
BOOL  force = FALSE 
) [static, inherited]

Change the specified files name. This does not move the file in the directory hierarchy, it only changes the name of the directory entry.

The newname# parameter must consist only of the file name part, as returned by the PFilePath::GetFileName()# function. Any other file path parts will cause an error.

The first form uses the file path specification associated with the instance of the object. The name within the instance is changed to the new name if the function succeeds. The second static function uses an arbitrary file specified by name.

TRUE if the file was renamed.
oldname  Old name of the file.
newname  New name for the file.
force  Delete file if a destination exists with the same name.

Definition at line 805 of file ptlib.cxx.

References PFile::Exists(), PString::FindOneOf(), PFilePath::GetDirectory(), and PFile::Remove().

  if (newname.FindOneOf(":\\/") != P_MAX_INDEX) {
#ifdef _WIN32_WCE
    errno = EINVAL;
#endif // _WIN32_WCE
    return FALSE;
  PString fullname = oldname.GetDirectory() + newname;
  if (rename(oldname, fullname) == 0)
    return TRUE;
  if (!force || errno == ENOENT || !Exists(fullname))
    return FALSE;
  if (!Remove(fullname, TRUE))
    return FALSE;
  return rename(oldname, fullname) == 0;

Generated by  Doxygen 1.6.0   Back to index