通过函数传递文件的完整路径(例如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
我应该知道有好多是建立在只为这:)谢谢API调用! – Mark 2009-11-30 14:08:50
要翻译C#代码,只需删除分号。 C#是如此罗嗦:) – MarkJ 2009-11-30 17:25:28