给定一个文件的完整路径,例如 C:\someFolder\anotherFolder\someXML.xml
,判断该文件夹是否存在。有没有更加智能、更好、更优雅的方法来实现这个功能?以下是我的实现代码:
Private Function FolderExists(ByVal fullPath As String) As Boolean
Dim folders() As String = fullPath.Split("\")
Dim folderPath As String = ""
For i As Integer = 0 To folders.Length - 2 'subtract 2 to avoid appending the filename.
folderPath += folders(i) + "\"
Next
Dim f As New DirectoryInfo(folderPath)
Return f.Exists
End Function