다음을 통해 공유


CFile::SetFilePath

파일의 경로 지정 하려면이 함수를 호출 합니다. 예를 들어, 파일의 경로 때 사용할 수 없는 경우는 CFile 개체는 생성 되 고 호출 SetFilePath 이 제공 합니다.

virtual void SetFilePath( 
   LPCTSTR lpszNewName  
);

매개 변수

  • lpszNewName
    새 경로 지정 하는 문자열에 대 한 포인터입니다.

설명

참고

SetFilePath파일 열기 또는 파일 생성 하지. 단지와 연결 된 CFile 개체를 경로 이름으로 사용 될 수 있습니다.

예제

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
} 

요구 사항

헤더: afx.h

참고 항목

참조

CFile 클래스

계층 구조 차트

CFile::GetFilePath

CFile::CFile