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