.net - One Drive 文件夹的 .NET Directory.Move() 失败
问题描述
对于通话:
// 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
为什么这不起作用?我能做些什么来解决它?
解决方案
目的地需要在路径的末尾有一个 \。
string destDirectory = Path.Combine(backupFolder, Path.GetFileName(path));
if ((!destDirectory.EndsWith("\\")) && !destDirectory.EndsWith("/"))
destDirectory += "\\";
推荐阅读
- c++ - delete[] 的析构函数问题
- android - 外投影类型禁止使用方法
- azure - VMSS 自定义映像的优缺点
- angular - 在 Edge 中渲染 PDF,在嵌入中渲染 IE11
- javascript - 在 React 中播放依赖于状态的音频文件
- c# - Microsoft.CognitiveServices.Speech.SpeechRecognizer - 获取文件中结果的时间偏移,持续识别
- mysql - 插入两个表不起作用。有正确的方法吗?
- python - 计算行数并以更少的数量打印
- vim - 在vim中替换匹配分隔符内的单个字符
- java - 在 ListView 中从 XML 资源文件添加项目