我正在尝试将一些文件从一个目录移动到同一驱动器上的另一个目录中。所有目标目录都存在但MoveFile()
不起作用并GetLastError()
返回 0。我是 C++ 新手,我不知道是什么导致了这个问题。这是代码:
try
{
destinationFilePath = i->FilePath;
destinationFilePath=destinationFilePath.substr(destinationFilePath.find(GENERAL_SAVE_PATH) + strlen(GENERAL_SAVE_PATH.c_str()));
destinationFilePath = Backup_Save_Path + destinationFilePath;
vector<string> folders;
StringSplit(destinationFilePath,"\\",folders);
string pathToCreate;
string backSlash = "\\";
for(vector<string>::const_iterator j = folders.begin(); j != folders.end(); ++j)
{
pathToCreate += j->c_str() + backSlash;
if (pathToCreate.find(".txt") == std::string::npos)
CreateBackupFolders(pathToCreate);
}
if (MoveFile(lastExportedFilePath.c_str(),destinationFilePath.c_str()))
AfxMessageBox("moved");
else
{
DWORD dw = GetLastError();
AfxMessageBox("Couldn't move");
}
lastExportedFilePath = i->FilePath;
}
catch(...)
{
Log(LOG_PATH_LOG_INSERTING, LOG_TYPE_EXCEPTION, "ExportLogsToDB()", "Move", destinationFilePath, "");
}