繁体   English   中英

CFile复制方法修复文件访问被拒绝的问题

[英]CFile Copy Method to fix file access denied issue

我的应用遇到了拉面错误。 当生成新文件且文件大小为0K时,拒绝txt文件访问。

我只想复制现有文件并在关闭当前文件后将其重命名。

有人可以给我一种复制文件的方法吗? 谢谢。

我的代码段如下。

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());
        }

我认为我的应用错误是由上述代码引起的。

CFile没有复制文件的方法。

使用:: CopyFile()函数可以简单地复制文件,而无需打开和关闭文件。

是CFile没有复制文件的方法。 您可以使用以前发布的:: CopyFile Win32方法,也可以使用CFile的另一种(小的复杂方式),请参见CFile :: Open方法中的示例

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM