2
我知道有验证IPAdresses在PowerShell中的便捷方式:是否有用于验证文件和路径名的类型加速器?
[ipaddress]"12.12.12.12"
[ipaddress]"12.12.12.812" #Throws an Error.
你知道,如果有一个类似的方法来验证文件级和路径名? 如
[path]"c:\temp\t?est.txt" #Throws an Error
我知道有验证IPAdresses在PowerShell中的便捷方式:是否有用于验证文件和路径名的类型加速器?
[ipaddress]"12.12.12.12"
[ipaddress]"12.12.12.812" #Throws an Error.
你知道,如果有一个类似的方法来验证文件级和路径名? 如
[path]"c:\temp\t?est.txt" #Throws an Error
可以使用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
在这样的描述看,似乎不是要告诉你是否该文件或路径实际上存在。这只是对参数进行语法检查。 - 编辑没关系。这正是要求的。咄。 – mjolinor 2013-04-21 15:18:54
是真的,但ipaddress也是这样,它不会告诉你ip是否退出,它只是验证它。我们可以发出第二个电话来验证它的存在,反之亦然,以防我不在OP之下。 – 2013-04-21 15:22:22
是的,我只想验证一个参数: [ValidateScript({Test-Path $ _ -IsValid})] \t [string] $ logfilepath 适合我。谢谢谢伊! – icnivad 2013-04-21 15:23:48