C# 中的 DirectoryNotFoundException
programmingserver side programmingcsharp更新于 2025/11/25 0:44:00
如果您尝试查找的目录不存在,则会发生 DirectoryNotFoundException。
在这里,我们尝试使用 GetDirectories() 方法查找不存在的目录。
示例
using System.IO;
using System;
class Program {
static void Main() {
Directory.GetDirectories("D:\
ew\");
}
}
由于目录"D:\
ew"不存在,上述代码将生成以下异常。
Unhandled Exception: System.IO.DirectoryNotFoundException: Could not find a part of the path

