我在 Visual Basic 中使用 GetFileSystemEntries() 来获取驱动器的完整结构,我使用了在 MSDN 中发现的异常来处理错误,但我不知道如何传递给我错误的目录并保存我阵列中的其他人。
这是我的代码:
Dim array()
Try
array = System.IO.Directory.GetFileSystemEntries("C:\", "*", System.IO.SearchOption.AllDirectories)
For Each x As System.String In array
list_Drives.Items.Add(x)
Next
Catch exp As UnauthorizedAccessException
System.Console.WriteLine("I don't have permission here")
Catch exp As ArgumentNullException
System.Console.WriteLine("Path is a null reference.")
Catch exp As System.Security.SecurityException
System.Console.WriteLine("The caller does not have the " + _
"required permission.")
Catch exp As ArgumentException
System.Console.WriteLine("Path is an empty string, " + _
"contains only white spaces, " + _
"or contains invalid characters.")
Catch exp As System.IO.DirectoryNotFoundException
System.Console.WriteLine("The path encapsulated in the " + _
"Directory object does not exist.")
End Try
谢谢