Hi. I have a very simple sample program that causes OneDrive to produce the error dialog "You now have two copies of a file...We couldn't merge the changes in "XXXXX' so we created another copy of it."
This is causing us some application problems on desktop windows 11 where the Documents folder is now mapped to OneDrive.
Is there a Microsoft tutorial/document that explains what "not to do" or "how best to work" with OneDrive when it comes to application development that actively uses the Documents folder?
Below is simple C++ program that reproduces Merge the problem. Make sure to run the setup steps to create files/folder.
// renamer.cpp
#include <iostream>
#include <filesystem>
#include <fstream>
#include "Windows.h"
using namespace std;
int main()
{
// Setup:
// create a folder in the Onedrive path named nametest
// inside nametest folder create another folder in the Onedrive path named project1
// create a file in the project1 folder named project1.optix
// put any text in the project1.optix file
// update the <OneDrive> path strings below to match the location in which these files and folders are created
auto const oldFileAndFolderName = "project1";
auto const newFileAndFolderName = "project2";
string oldFolderPath = "<OneDrive path>\\nametest\\project1";
string newFolderPath = "<OneDrive path>\\nametest\\project2";
// open current file, change content, save
ofstream projectFile;
string concatString = "\\";
string oldFileAbsolutepath = oldFolderPath + concatString + oldFileAndFolderName + ".optix";
projectFile.open(oldFileAbsolutepath, ios_base::app);
projectFile << newFileAndFolderName;
projectFile << endl;
projectFile.close();
// rename folder
MoveFileA(oldFolderPath.c_str(), newFolderPath.c_str());
// rename file
string renamedFileAbsolutepath = newFolderPath + concatString + oldFileAndFolderName + ".optix";
string newFileAbsolutepath = newFolderPath + concatString + newFileAndFolderName + ".optix";
MoveFileA(renamedFileAbsolutepath.c_str(), newFileAbsolutepath.c_str());
}