HANDLE hFile = CreateFile( "c:\\test.bmp", GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );CREATE_ALWAYS: Creates a new file. If the file exists, the function overwrites the file and clears the existing attributes.
CFileException m_Except;
CFileFind m_find1;
CString m_findstr;
m_findstr="文件路径";
if(!m_find1.FindFile(m_findstr))
{
m_File.Open(findstr, CFile::modeCreate, &m_Except);
m_File.Close();
}
CFileFind finder;
if(!finder.FindFile(lpszFile))
{
CStdioFile file;
if(!file.Open(lpszFile,CFile::modeCreate|CFile::modeWrite))
{
return;//创建失败返回
}
...//创建成功
file.WriteString(...);
file.Close();
}
GENERIC_WRITE,
FILE_SHARE_WRITE,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL );CREATE_ALWAYS: Creates a new file. If the file exists, the function overwrites the file and clears the existing attributes.
CStdioFile fLogFile;
CFileFind fFind;
if ( !fFind.FindFile(sFilePath, 0) )
{
//create log file
if ( !fLogFile.Open(sFilePath, CFile::modeCreate | CFile::modeWrite) )
{
//error
CErrMsg errMsg;
errMsg.GetWarningErr(LOG_FILE_WRITE_ERR, sFilePath);
bRtn = FALSE;
}
......