CFile::Rename

This static function renames the specified file.

static void PASCAL Rename( 
   LPCTSTR lpszOldName, 
   LPCTSTR lpszNewName  
);

lpszOldName

The old path.

lpszNewName

The new path.

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

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();
}

Header: afx.h

Community Additions

ADD
Show: