I have a directory D:\AAAA\BBBB\CCCC and using C# I want to move this directory to D:\DDDD.
Result I want to achieve is the directory at: D:\DDDD\AAAA\BBBB\CCCC
I am using following line of code:
System.IO.Directory.Move("D:\\AAAA","D:\\DDDD");
But it throws an System.IOException with the message:
Cannot create a file when that file already exists.
Please guide me.
If you are looking for something more like a merge to an already existing directory, then I think the only way to do it is to write your own method to create the directories and move the files manually (like Tim Schmelter’s comment). Otherwise, you could delete an existing directory if it exists first, but that seems dangerous.
Here is a SO about merging. The answer is a Copy, so just add a final delete for the origin if you want something closer to a move