我想检查用户给出的路径是 vbscript 中的目录或文件。有没有正则表达式或其他方法可以做到这一点?任何帮助都会很棒。
Function GetFSElementType( ByVal path )
With CreateObject("Scripting.FileSystemObject")
path = .GetAbsolutePathName( path )
Select Case True
Case .FileExists(path) : GetFSElementType = 1
Case .FolderExists(path) : GetFSElementType = 2
Case Else : GetFSElementType = 0
End Select
End With
End Function
Function IsFile( path )
IsFile = ( GetFSElementType(path) = 1 )
End Function
Function IsFolder( path )
IsFolder = (GetFSElementType(path) = 2 )
End Function
Function FSExists( path )
FSExists = (GetFSElementType(path) <> 0)
End Function
WScript.Echo CStr( IsFile("c:\") )
WScript.Echo CStr( IsFolder("c:\") )
WScript.Echo CStr( FSExists("c:\") )
Run Code Online (Sandbox Code Playgroud)