【发布时间】:2019-09-29 20:29:37
【问题描述】:
我正在尝试通过以下方式在名称上附加时间戳来移动和重命名文件:
private void MoveFile(string from, string to, string filename) {
File.Move(from, System.IO.Path.Combine(to, filename + DateTime.Now.ToString().Replace(":", "-")));
}
我这样称呼它:
MoveFile(currentPath, outputFolderPath, System.IO.Path.GetFileName(currentPath));
这会导致以下异常:
抛出异常:“System.IO.DirectoryNotFoundException”在 mscoorlib.dll。
如果我删除时间戳的附加,它会起作用。为什么会出现此错误?
【问题讨论】:
-
DateTime.Now.ToString().Replace(":", "-")=>29/09/2019 21-32-07-/导致问题 -
@LeonardoSeccia 关注,谢谢!
标签: c# system.io.file