2012-04-25 98 views
0

我的應用遇到了ramdon錯誤。生成新文件時,txt文件訪問被拒絕,並且其大小爲0K。CFile複製方法修復被拒絕的文件訪問問題

我只想複製現有文件並在關閉當前文件後重命名它。

任何人都可以給我一種方法來複制文件?謝謝。

我的代碼片段如下。

ofstream m_LogFile; 

CFile logcfile; 

if(dwLength > 1024*1024*10) 
     { 
      string fileDate = status.m_mtime.Format("%Y%m%d%H%M%S");   
      string modulePath = Util::GetModulePath(); 
      string fileNewName(modulePath); 
      fileNewName += "mytextlog" + fileDate + ".txt"; 
      m_LogFile.close(); 
          // I want to insert CFile copy method before rename it. 
      logcfile.Rename(m_sLogFileName.c_str(), fileNewName.c_str()); 
      m_LogFile.open(m_sLogFileName.c_str(), ios::out | ios::app); 
      _findfile(modulePath.c_str()); 
     } 

我假設我的應用程序錯誤是由上面的代碼引起的。

回答

1

CFile沒有複製文件的方法。

使用:: CopyFile()函數可以簡單地複製文件而無需打開和關閉文件。

0

是CFile沒有複製文件的方法。您可以使用之前發佈的:: CopyFile Win32方法,或者使用另一種(很複雜的)方法,例如使用CFile在CFile::Open方法中的示例