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

Mark Winney 0 Reputation points
2023-11-09T15:55:20.5+00:00

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());
}
C++
C++
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,690 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,857 questions
Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
9,455 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Emi Zhang-MSFT 24,601 Reputation points Microsoft Vendor
    2023-11-10T00:23:40.79+00:00

    Hi,

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

    https://techcommunity.microsoft.com/t5/onedrive-developer/bd-p/OneDriveDeveloper

    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

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.