简体   繁体   English

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

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

My app met a ramdon error. 我的应用遇到了拉面错误。 the txt file access denied when the new file generated and it's size is 0K. 当生成新文件且文件大小为0K时,拒绝txt文件访问。

I just want to copy the existing file and rename it after closed the current one. 我只想复制现有文件并在关闭当前文件后将其重命名。

Could anyone give me a method to Copy a file? 有人可以给我一种复制文件的方法吗? Thanks. 谢谢。

my code snippet as below. 我的代码段如下。

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

I assumed that my app error caused by the code above. 我认为我的应用错误是由上述代码引起的。

CFile does not have a method to copy a file. CFile没有复制文件的方法。

Use the ::CopyFile() function to simply copy a file without any need to open and close the file. 使用:: CopyFile()函数可以简单地复制文件,而无需打开和关闭文件。

Yes CFile does not have a method to copy file. 是CFile没有复制文件的方法。 You could use ::CopyFile Win32 method as posted before, or there is another (little complicated) way with CFile see example at CFile::Open method 您可以使用以前发布的:: CopyFile Win32方法,也可以使用CFile的另一种(小的复杂方式),请参见CFile :: Open方法中的示例

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

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