我遇到了将目录拉入列表的代码的问题。它在我的机器上运行良好,它们都存在,但是当我在另一个没有它们的机器上运行时,它无法加载列表并给出未处理的异常(System.IO.DirectoryNotFoundException:找不到路径的一部分'C:\Alerton..)。我需要检查所有目录,但如果它们不存在,我只需跳过并查找下一个。在此先感谢,如果这是我忽略的一件简单的事情,我很抱歉。
Private Sub getjobs(sender As Object, e As EventArgs) 处理 MyBase.Load
For Each Dir As String In Directory.GetDirectories("C:\Alerton\Compass\1.0\ATSINC")
ListBox1.Items.Add(Dir & "\ddc")
'Console.WriteLine(Dir)
Next
For Each Dir As String In Directory.GetDirectories("C:\Alerton\Compass\1.5.1\ATSINC")
ListBox1.Items.Add(Dir & "\ddc")
'Console.WriteLine(Dir)
Next
For Each Dir As String In Directory.GetDirectories("C:\Alerton\Compass\1.6.4\ATSINC")
ListBox1.Items.Add(Dir & "\ddc")
'Console.WriteLine(Dir)
Next
For Each Dir As String In Directory.GetDirectories("C:\Alerton\Compass\1.6.5\ATSINC")
ListBox1.Items.Add(Dir & "\ddc")
'Console.WriteLine(Dir)
Next
For Each Dir As String In Directory.GetDirectories("C:\Alerton\Bactalk\3.0\ATSINC")
ListBox1.Items.Add(Dir & "\ddc")
'Console.WriteLine(Dir)
Next
For Each Dir As String In Directory.GetDirectories("C:\Alerton\Bactalk\3.1\ATSINC")
ListBox1.Items.Add(Dir & "\ddc")
'Console.WriteLine(Dir)
Next
End Sub