You can use FileAttributes
class:
'get the file attributes for file or directory
FileAttributes attr = File.GetAttributes("c:\Temp")
'detect whether its a directory or file
If ((attr & FileAttributes.Directory) = FileAttributes.Directory) Then
MessageBox.Show("Its a directory")
Else
MessageBox.Show("Its a file")
End IF
Or you can use the Uri
class:
Private IsLocalPath(Byval p As String) As Boolean
Return New Uri(p).IsFile
End Function
You can enhance this method to include support for certain invalid URIs:
Private IsLocalPath(Byval p As String) As Boolean
If (p.StartsWith("http:")) Then
Return False
End IF
Return New Uri(p).IsFile
End Function
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…