通过将函数传递到文件的完整路径(例如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