.NET Directory.Move() fails for One Drive folders

0

For the call:

// Directory.Exists(path) returns true
// path = "C:\\Users\\david\\OneDrive - Windward Studios\\Documents\\AutoTag\\templates"
Directory.CreateDirectory(backupFolder);
Directory.Move(path, Path.Combine(backupFolder, Path.GetFileName(path)));

Throws the exception:

System.IO.IOException
  HResult=0x80070005
  Message=Access to the path 'C:\Users\david\OneDrive - Windward Studios\Documents\AutoTag\templates' is denied.
  Source=mscorlib
  StackTrace:
   at System.IO.Directory.InternalMove(String sourceDirName, String destDirName, Boolean checkHost)
   at System.IO.Directory.Move(String sourceDirName, String destDirName)
   at AutoTagCore.net.windward.autotag.controls.options.CopyTemplates.UpdateFiles() in C:\git\Jenova\autotag\AutoTagCore\net\windward\autotag\controls\options\CopyTemplates.cs:line 480

  This exception was originally thrown at this call stack:
    System.IO.Directory.InternalMove(string, string, bool)
    System.IO.Directory.Move(string, string)
    AutoTagCore.net.windward.autotag.controls.options.CopyTemplates.UpdateFiles() in CopyTemplates.cs

Why doesn't this work? And what can I do to fix it?

.net
system.io.directory
asked on Stack Overflow Mar 4, 2020 by David Thielen

1 Answer

0

The destination needs to have an \ at the end of the path.

                    string destDirectory = Path.Combine(backupFolder, Path.GetFileName(path));
                    if ((!destDirectory.EndsWith("\\")) && !destDirectory.EndsWith("/"))
                        destDirectory += "\\";
answered on Stack Overflow Mar 5, 2020 by David Thielen

User contributions licensed under CC BY-SA 3.0