Share via


CFile::Rename

This static function renames the specified file.

static void PASCAL Rename( 
   LPCTSTR lpszOldName, 
   LPCTSTR lpszNewName, 
   CAtlTransactionManager* pTM = NULL 
);

Parameters

  • lpszOldName
    The old path.

  • lpszNewName
    The new path.

  • pTM
    Pointer to CAtlTransactionManager object

Remarks

Directories cannot be renamed. This is equivalent to the REN command.

Example

TCHAR* pOldName = _T("Oldname_File.dat");
TCHAR* pNewName = _T("Renamed_File.dat");

try
{
    CFile::Rename(pOldName, pNewName);
}
catch(CFileException* pEx )
{
    TRACE(_T("File %20s not found, cause = %d\n"), pOldName, 
       pEx->m_cause);
    pEx->Delete();
}

Requirements

Header: afx.h

See Also

Reference

CFile Class

Hierarchy Chart