首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >.NET Directory.Move()对一个驱动器文件夹失败

.NET Directory.Move()对一个驱动器文件夹失败
EN

Stack Overflow用户
提问于 2020-03-04 22:03:04
回答 1查看 68关注 0票数 0

为呼吁:

代码语言:javascript
复制
// 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)));

抛出异常:

代码语言:javascript
复制
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

为什么这个不行?我能做些什么来解决这个问题?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-03-05 16:56:20

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

代码语言:javascript
复制
                    string destDirectory = Path.Combine(backupFolder, Path.GetFileName(path));
                    if ((!destDirectory.EndsWith("\\")) && !destDirectory.EndsWith("/"))
                        destDirectory += "\\";
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60535385

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档