Share via

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

Anonymous
2023-11-03T19:04:53+00:00

Hi.

FYI - none of what is happening below is a problem with the regular file system.

We have an application that is storing a set of text files (YAML) to a subdirectory of Documents, which is mapped to OneDrive.

Lets call this subdirectory "Library1" and it contains YAML files such as "Library1.yaml".

This YAML file also contains text referencing "Library1".

We have ability to rename this library from within the application. If I rename "Library1" to "Library2" the code performs the following steps:

  • Rename the Library1 folder to Library2
  • Update Library2/Library1.yaml file content to "Library2"
  • Rename the Library2/Library1.yaml to Library2/Library2.yaml.

Problem is when the sync process executes it produces an 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."

We end up with 2 files, Library2.yaml and Library2-ABC.yaml

Library2.yaml does not contains the changes and Library2-ABC.yaml contains the all the correct changes.

My assumption is that changing the file content and also renaming the file is causing OneDrive problems merging the changes...it is seeing conflicts perhaps.

I did try the "Always keep on the device" option on the parent folder and this did not help.

I assume disabling the sync for the Library folder is another option...but I cannot see any ability to do this when creating a folder from within the code.

I cannot see anyway around this problem, code-wise, without doing the file/folder operations outside OneDrive (such as a temporary directory) and then copying the folder back to OneDrive.

Any alternative suggestions would be appreciated. Thanks

Windows for home | Windows 11 | Files, folders, and storage

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

3 answers

Sort by: Most helpful
  1. Anonymous
    2023-11-09T09:18:58+00:00

    Hello,Mark Winney

    Thank you for sharing your program with the community, but the issue you are asking about is beyond the scope of our forum support, and we do not have the consulting expertise to help you with this issue. There are more specialized technical engineers at Microsoft Learn who can help you with your development questions, so thank you for your understanding!

    Best Regards

    Rota Ye |Microsoft Community Support Specialist

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2023-11-07T20:55:45+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());
    }
    

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2023-11-04T09:21:08+00:00

    Hello,Mark Winney

    Thank you for posting in the Microsoft community.

    I read your description in full, but based on the needs you mentioned, OneDrive is not well suited for storing some files that are updated frequently and locally, perhaps you can use a file server, etc. to accomplish what you need. In addition, I suggest you post this question in the Microsoft Learn (English only, you can use the translation tool to help communication) release which is intended for advanced users like you, maybe there will be other ways for you to achieve this functionality through OneDrive.

    You can ask a question by clicking "Ask a Question" and an expert in the field can provide a more specialized solution.

    I can't help you with this, but I'll keep the question on file in case one of our wonderful volunteers comes up with an idea for you.

    Best Regards,

    Rota Ye |Microsoft Community Support Specialist

    Was this answer helpful?

    0 comments No comments