Home > Article > Backend Development > DirectoryNotFoundException in C#
DirectoryNotFoundException occurs if the directory you are looking for does not exist.
Here, we try to use the GetDirectories() method to find a directory that does not exist.
using System.IO; using System; class Program { static void Main() { Directory.GetDirectories("D:\ew\"); } }
Since the directory "D:\
ew" does not exist, the above code will generate the following exception.
Unhandled Exception: System.IO.DirectoryNotFoundException: Could not find a part of the path
The above is the detailed content of DirectoryNotFoundException in C#. For more information, please follow other related articles on the PHP Chinese website!