Compartilhar via


CFile::GetFileName

Chame essa função de membro para recuperar o nome de um arquivo especificado.

virtual CString GetFileName( ) const;

Valor de retorno

O nome do arquivo.

Comentários

Por exemplo, quando você chamar GetFileName para gerar uma mensagem ao usuário sobre o arquivo c:\windows\write\myfile.wri, o nome de arquivo myfile.wri, será retornado.

Para retornar o caminho completo do arquivo, incluindo o nome, telefonar GetFilePath.Para retornar o título do arquivo (myfile), ligue para GetFileTitle.

Exemplo

Este fragmento de código abre o arquivo sistema.ini no seu diretório do WINDOWS.Se encontrado, o exemplo imprimirá o nome e o caminho e o título, sistema autônomo mostrada em saída:

try
{
   // try to open the file
   CFile sysFile(_T("C:\\WINDOWS\\SYSTEM.INI"), CFile::modeRead);

   // print out path name and title information
   _tprintf_s(_T("Path is : \"%s\"\n"),
      (LPCTSTR) sysFile.GetFilePath());
   _tprintf_s(_T("Name is : \"%s\"\n"),
      (LPCTSTR) sysFile.GetFileName());
   _tprintf_s(_T("Title is: \"%s\"\n"), 
      (LPCTSTR) sysFile.GetFileTitle());

   // close the file handle
   sysFile.Close();
}
catch (CFileException* pEx)
{
   // if an error occurs, just make a message box
   pEx->ReportError();
   pEx->Delete();
}

Saída

Path is : "C:\WINDOWS\SYSTEM.INI"

Name is : "SYSTEM.INI"

Title is: "System"

Requisitos

Cabeçalho: afx.h

Consulte também

Referência

Classe CFile

Gráfico de hierarquia

CFile::GetFilePath

CFile::GetFileTitle

Outros recursos

CFile membros