Compartilhar via


CFile::SetFilePath

Chamar esta função para especificar o caminho do arquivo; por exemplo, se o caminho de um arquivo não está disponível quando um CFile objeto é construído, telefonar SetFilePath para fornecer a ele.

virtual void SetFilePath(
   LPCTSTR lpszNewName 
);

Parâmetros

  • lpszNewName
    Ponteiro para uma seqüência de caracteres especificando o novo caminho.

Comentários

Observação:

SetFilePath não em em aberto o arquivo ou criar o arquivo; ele simplesmente associa o CFile objeto com um nome de caminho, que pode ser usado.

Exemplo

TCHAR* pstrName = _T("C:\\test\\SetPath_File.dat");

// open a file
HANDLE hFile = ::CreateFile(pstrName, GENERIC_WRITE, FILE_SHARE_READ,
   NULL, CREATE_ALWAYS, 0, NULL);

if (hFile != INVALID_HANDLE_VALUE)
{
   // attach a CFile object to it
   CFile myFile(hFile);

   // At this point, myFile doesn't know the path name for the file
   // it owns because Windows doesn't associate that information
   // with the handle. Any CFileExceptions thrown by this object
   // won't have complete information.

   // Calling SetFilePath() remedies that problem by letting CFile
   // know the name of the file that's associated with the object.

   myFile.SetFilePath(pstrName);

   // write something to the file and flush it immediately
   DWORD dwValue = 1234;
   myFile.Write(&dwValue, sizeof(dwValue));
   myFile.Flush();

   // destroying the CObject here will call ::CloseHandle() on the file
} 

Requisitos

Cabeçalho: afx.h

Consulte também

Referência

Classe CFile

Gráfico de hierarquia

CFile::GetFilePath

CFile::CFile

Outros recursos

CFile membros