是否有用于验证文件名和路径名的类型加速符



我知道在Powershell中有一种方便的方法来验证ipaddress:

[ipaddress]"12.12.12.12"

[ipaddress]"12.12.12.812" #Throws an Error.

你知道是否有类似的方法来验证文件名和路径名吗?如

[path]"c:tempt?est.txt" #Throws an Error

您可以使用Test-Path cmdlet:

Test-Path "c:tempt?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

最新更新