指定したパス情報がファイルかフォルダ(ディレクトリー)か判断する。

指定したパス情報がファイル名かフォルダ名か判断するにはSystem.IO.File.Exists関数とSystem.IO.Directory.Exists関数を使います。File.Exists関数は、指定したパスがフォルダとして存在している場合でもファイルではない場合はFalseを返します。また、Directory.Exists関数は、指定したパスがファイルとして存在している場合でも、フォルダではない場合はFalseを返します。この特性を利用して以下のように判定します。


Public Enum FileSystemType
None = 1
File
Directory
End Enum

Public Function GetFileSystemType(ByVal path As String) As FileSystemType

If System.IO.File.Exists(path) = True Then
Return FileSystemType.File
ElseIf System.IO.Directory.Exists(path) = True Then
Return FileSystemType.Directory
Else
Return FileSystemType.None
End If

End Function