【发布时间】:2023-03-30 02:00:02
【问题描述】:
通过向函数传递文件的完整路径(例如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
【问题讨论】:
标签: .net vb.net path-manipulation