2013-04-21 42 views

回答

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 
+0

在這樣的描述看,似乎不是要告訴你是否該文件或路徑實際上存在。這只是對參數進行語法檢查。 - 編輯沒關係。這正是要求的。咄。 – mjolinor 2013-04-21 15:18:54

+0

是真的,但ipaddress也是這樣,它不會告訴你ip是否退出,它只是驗證它。我們可以發出第二個電話來驗證它的存在,反之亦然,以防我不在OP之下。 – 2013-04-21 15:22:22

+0

是的,我只想驗證一個參數: [ValidateScript({Test-Path $ _ -IsValid})] \t [string] $ logfilepath 適合我。謝謝謝伊! – icnivad 2013-04-21 15:23:48

相關問題