파일 상태를 읽으려면

  • CFile 클래스를 사용하여 파일 정보를 읽고 설정합니다. CFile 정적 멤버 함수인 GetStatus를 사용하여 파일의 존재 여부를 확인할 수 있습니다. 지정된 파일이 존재하지 않으면 GetStatus가 0을 반환합니다.

따라서 GetStatus 결과를 사용하여 다음 예제와 같이 파일을 열 때 CFile::modeCreate 플래그의 사용 여부를 결정할 수 있습니다.

CFile theFile;
char* szFileName = "c:\\test\\myfile.dat";
BOOL bOpenOK;

CFileStatus status;
if( CFile::GetStatus( szFileName, status ) )
{
    // Open the file without the Create flag
    bOpenOK = theFile.Open( szFileName, 
                    CFile::modeWrite );
}
else
{
    // Open the file with the Create flag
    bOpenOK = theFile.Open( szFileName, 
                    CFile::modeCreate | CFile::modeWrite );
}

[출처 : http://msdn.microsoft.com/ko-kr/library/cc451414(VS.71).aspx]

+ Recent posts