我知道有一种方便的方法可以在Powershell中验证IP地址:
[ipaddress]"12.12.12.12"
[ipaddress]"12.12.12.812" #Throws an Error.
您知道是否有类似的方法来验证文件和路径名? e.g
[path]"c:\temp\t?est.txt" #Throws an Error
答案 0 :(得分:6)
您可以使用Test-Path
cmdlet:
Test-Path "c:\temp\t?est.txt" -IsValid
来自帮助:
PS> help test-path -param isvalid
-IsValid [<SwitchParameter>]
Determines whether the syntax of the path is correct, regardless of whether the elements of the path exist. This
parameter returns TRUE if the path syntax is valid and FALSE if it is not.
Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false