2013-04-21 41 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

相关问题