Application has problems renaming/modifying files on OneDrive and produce "We couldn't merge the changes..."

Mark Winney 0 Reputation points

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";, ios_base::app);
	projectFile << newFileAndFolderName;
	projectFile << endl;
	// 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());
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,329 questions
Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,062 questions
Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
6,818 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Emi Zhang-MSFT 19,131 Reputation points Microsoft Vendor


    I suggest you post this thread to OneDrive for Developer forum:

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.

    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments