如何编程实现MFC创建新文件夹

如何编程实现MFC创建新文件夹,第1张

CString   strFolderPath="c:\\test"   

  //   判断路径是否存在   

  if   (!PathIsDirectory(m_strFolderPath)   )   

  {   

      CString   strMsg   

      strMsg.Format   ("指定路径\"%s\"不存在,是否创建?",   m_strFolderPath)   

      if   (AfxMessageBox(strMsg,   MB_YESNO)   ==   IDYES)   

      {   

          if   (!CreateDirectory(m_strFolderPath,   NULL))//here

          {   

                strMsg.Format   ("创建路径\"%s\"失败!是否继续?",   m_strFolderPath)   

                if   (AfxMessageBox(strMsg,   MB_YESNO)   ==   IDYES)   

                      return   

            }   

      }   

  }

其实就是一个函数:CreateDirectory

void C文件读写Dlg::OnWriteButton()

{

char* pszFileName="F:\\myfile.txt"

CStdioFile myFile

CFileException fileException

if(myFile.Open(pszFileName,CFile::typeText|CFile::modeCreate|CFile::modeReadWrite|CFile::modeNoTruncate),&fileException)

{

CString strOrder

strOrder.Format("%d,%.3f\t",66,88.88)

myFile.WriteString(strOrder)

myFile.Close() }

else

{

TRACE("Can't open file %s,error=%u\n",pszFileName,fileException.m_cause)

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/tougao/8088942.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-13
下一篇 2023-04-13

发表评论

登录后才能评论

评论列表(0条)

保存