如果断电,mkdir和copyFile不完整
Incomplete mkdir and copyFile if power lost
我有一个应用程序,它可以创建一个目录并将文件复制到其中。但是,如果窗口正确关闭并且电源丢失,文件将不总是可用或完整的。
我的操作系统是Windows Embedded POSReady7(版本6.1 Build 7601:Service Pack 1),硬盘上的"写缓存"选项已禁用。我有一个C++应用程序。我也使用过刷新(_F),但没有帮助。
我已经写了一个测试应用程序,我可以在那里看到问题。我启动应用程序,在输出完成后等待十秒钟,然后拔下电源。重新启动后,这些文件不可用。
这是我的代码:
#include "stdafx.h"
#include <iostream>
#include <direct.h>
#include <string>
#include <Windows.h>
#include <atlstr.h>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
string csPathName("D:\temp\FileCopyTest\");
int mkRetValue = _mkdir( csPathName.c_str() );
cout << "Create directory " << csPathName.c_str() << " with return value " << mkRetValue << endl;
BOOL copyRetValue = CopyFileEx( _T("D:\temp\test.txt"), _T("D:\temp\FileCopyTest\test.txt"), nullptr, nullptr, FALSE, COPY_FILE_NO_BUFFERING );
cout << "Copy file, return value " << copyRetValue << endl;
int flushRetValue = _flushall();
cout << "flush files: " << flushRetValue << endl;
char c;
cin >> c;
return 0;
}
您是否尝试过将副本放入范围内?
{
CopyFileEx( _T("D:\temp\test.txt"), _T("D:\temp\FileCopyTest\test.txt"), nullptr, nullptr, FALSE, COPY_FILE_NO_BUFFERING );
}
相关文章:
- 如何在C++中将SHGetKnownFolderPath输出提供给CopyFile
- 如何修复 CopyFile() 错误 5 - 访问被拒绝错误
- 在我可以从fopen打开文件时,CopyFile无法找到该文件
- 为什么 CopyFile2 取代了 CopyFile 和 CopyFileEx
- windows CopyFile的正确输入格式是什么
- 如何使用 CopyFile 将特定类型的文件从一个文件夹复制到另一个文件夹
- CopyFile失败,错误代码为3(error_PATH_NOT_FOUND)
- 是否存在跨平台版本的win32 CopyFile
- CopyFile 不适用于环境字符串,但仅适用于放置文件的标准目录。无论如何要克服这个?
- 如果断电,mkdir和copyFile不完整
- CopyFile/CopyFileEx不能在Windows Server 2008 R2 SP1 x64中工作
- copyfile function on Mac OS X