【ファイル・ディレクトリ 判別(VBS版)】


'戻り値)1:ファイル、2、フォルダー、0:エラー(存在しないパス)
Public Function GetFileOrFolder( _
    ByVal sChkTrgtPath _
)
    Dim oFileSys
    Dim bFolderExists
    Dim bFileExists
 
    Set oFileSys = CreateObject("Scripting.FileSystemObject")
    bFolderExists = oFileSys.FolderExists(sChkTrgtPath)
    bFileExists = oFileSys.FileExists(sChkTrgtPath)
    Set oFileSys = Nothing
 
    If bFolderExists = False And bFileExists = True Then
        GetFileOrFolder = 1 'ファイル
    ElseIf bFolderExists = True And bFileExists = False Then
        GetFileOrFolder = 2 'フォルダー
    Else
        GetFileOrFolder = 0 'エラー(存在しないパス)
    End If
End Function
 

最終更新:2017年03月21日 10:41