【发布时间】:2018-12-20 21:01:21
【问题描述】:
我知道Directory.Move(source, destination) 重命名文件夹的方法。但是当我在开头重命名带有~ 符号的目标文件夹时,出现错误。
System.NotSupportedException: 给定路径的格式不受支持。
这是我的代码:
string oldFolderPath = @"C:\Old";
string newFolderPath = "~" + oldFolderPath;
Directory.Move(oldFolderPath, newFolderPath);
System.IO.Path.InvalidPathChars中,以下字符无效:
" < > |
它没有列出波浪号,那我该怎么办?非常感谢。
【问题讨论】:
-
~用于 8.3 路径(如 dos,8 个字符 + 3 个扩展名),Windows 内部将其用于 8.3 文件夹/文件名 > 8 个字符的名称。我想这就是你不能使用它的原因。 -
可能 Path.Combine 是你需要在这里使用的 stackoverflow.com/questions/7348768/…