You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.

Forum Discussion

XiangZhou's avatar
XiangZhou
New member | Level 2
2 years ago

How to merge two folders with Dropbox.Net SDK?

Dear support, 

 

To rename a folder, I call the MoveV2Async(pathOld, pathNew). 

If the pathNew exists, it fails with an error "to/conflict/folder/". 

 

If the destination folder already exists, I'd like to merge the old folder including its contained files/subfolders to the destination folder. 

i.e. copy and replace the files/subfolders if they exist.  Is it possible? 

 

It seems to me that the three optional parameters in MoveV2Async are not for this purpose. Any other methods I can use?

 

Thanks 

 

Xiang 

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    XiangZhou Здравко is correct; the Dropbox API doesn't offer a way to merge folders like this directly, but I'll pass this along as a feature request. I can't promise if or when that might be implemented though. You'd need to handle this in your code like they described. If/when you need to move multiple items, using MoveBatchAsync can help.

    • DCProducer's avatar
      DCProducer
      New member | Level 2

      Has there been any progress on this? I've accidently created a duplicate of a large folder  and have been adding to both without realizing my error. I want to now merge without fear of losing something. Is this possible within Dropbox or some additional software/app?  Thank you!

      • Greg-DB's avatar
        Greg-DB
        Icon for Dropbox Staff rankDropbox Staff

        DCProducer No, I don't have an update on this feature request for the Dropbox API.

         

        Note that this thread is regarding some functionality for the Dropbox API for use by developers. It's possible someone has already developed an app as a solution for this scenario, but unfortunately I can't offer guidance on third party apps like that.

    • XiangZhou's avatar
      XiangZhou
      New member | Level 2

      Thanks for your suggestion. 

       

      I am trying to implement it manually by deleting files in the destination folder firstly if exist and then move the files. 

       

      After calling the DeleteBatchV2Async, how do I safely wait until the files have been completely deleted before calling the  MoveBatchAsync. Could you show me some sample code?   

      • Greg-DB's avatar
        Greg-DB
        Icon for Dropbox Staff rankDropbox Staff

        I don't believe we have sample code for DeleteBatchAsync in particular unfortunately, but you should poll DeleteBatchCheckAsync to see when the job is done. Refer to the documentation linked there for more information.

         

        By the way, it looks like you mixed up DeleteBatchAsync with DeleteV2Async or MoveBatchV2Async; there's no DeleteBatchV2Async.

  • Здравко's avatar
    Здравко
    Legendary | Level 20

    Hi XiangZhou,

    As seems, there is no option to 'merge' files/folders using move by now. What you can do depends on what exactly you want achieve. If you just want to replace the existing folder, it becomes easy - delete the existing folder and move there the desired one (on the follow up try, after the remove). In such a way entire content of existing folder will gone (doesn't matter are there parts that don't overlap). If you want to keep non overlapping parts, you have to implement recursive algorithm that walk through the folder tree of the source folder and perform try move (eventually followed by delete and move) for files only. At the end, you'll need remove the source folder (there will be eventually empty subfolders only). If you want to merge files content further, then some content specific algorithms will also need as a part of the recursion.

    Hope this gives direction.

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

5,888 PostsLatest Activity: 3 hours ago
326 Following

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!