【问题标题】:.NET Directory.Move() fails for One Drive foldersOne Drive 文件夹的 .NET Directory.Move() 失败
【发布时间】:2020-06-17 11:54:31
【问题描述】:

来电:

// 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)));

抛出异常:

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

为什么这不起作用?我能做些什么来解决它?

【问题讨论】:

    标签: .net system.io.directory


    【解决方案1】:

    目的地需要在路径的末尾有一个\。

                        string destDirectory = Path.Combine(backupFolder, Path.GetFileName(path));
                        if ((!destDirectory.EndsWith("\\")) && !destDirectory.EndsWith("/"))
                            destDirectory += "\\";
    

    【讨论】:

      猜你喜欢
      • 2017-10-22
      • 1970-01-01
      • 2018-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-11
      • 2013-09-30
      • 1970-01-01
      相关资源
      最近更新 更多