![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Test-Path '' -IsValid does not return False but fails. Is this OK? Test-Path $Path -IsValid fails with ParameterBindingValidationException (Test-Path : Cannot bind argument to parameter 'Path' because it is...) is $Path is null or an empty string. As a result one has to check validity of $Path in this way: if ($Path -and (Test-Path $Path -IsValid)) {...} Is this intentional? -- Thanks, Roman Kuzmin PowerShellFar and FarNET: http://code.google.com/p/farnet/ |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Test-Path '' -IsValid does not return False but fails. Is this OK? There is no default value for -path (as opposed to get-childitem which lists the current directory), so it fails. You need to validate $path prior to testing it. -isValid can only run if the $path is not null or empty. You can see it by running: PS > test-path cmdlet test-path at command pipeline position 1 Supply values for the following parameters: Path[0]: Test-Path : Cannot bind argument to parameter 'Path' because it is an empty array. At line:1 char:9 + test-path <<<< Is it intensional? I think it is. Here's what the help says (it's required): PARAMETERS -path <string[]> Specifies a path to be tested. Wildcards are permitted. If the path includes spaces, enclose it in quotation marks. The parameter n ame ("-Path") is optional. Required? true ... ----- Shay Levi $cript Fanatic http://scriptolog.blogspot.com Quote: > Test-Path $Path -IsValid fails with > ParameterBindingValidationException (Test-Path : Cannot bind argument > to parameter 'Path' because it is...) is $Path is null or an empty > string. > > As a result one has to check validity of $Path in this way: if ($Path > -and (Test-Path $Path -IsValid)) {...} > > Is this intentional? > |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Test-Path '' -IsValid does not return False but fails. Is this OK? > Is it intensional? I think it is. Here's what the help says (it's Quote: > required): parameters are not the same as omitted parameters. $Path = '' Test-Path -Path $Path -IsValid Output: Test-Path : Cannot bind argument to parameter 'Path' because it is an empty string. .... Note, I do provide parameter -Path, so that 'required' is satisfied. But I rather expect Output: False than a failure message in this case. -- Thanks, Roman Kuzmin PowerShellFar and FarNET: http://code.google.com/p/farnet/ |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Test-Path '' -IsValid does not return False but fails. Is this OK? I can see what you mean. ----- Shay Levi $cript Fanatic http://scriptolog.blogspot.com Quote: Quote: >> Is it intensional? I think it is. Here's what the help says (it's >> required): >> > parameters are not the same as omitted parameters. > > $Path = '' > Test-Path -Path $Path -IsValid > Output: > Test-Path : Cannot bind argument to parameter 'Path' because it is an > empty > string. > ... > Note, I do provide parameter -Path, so that 'required' is satisfied. > But I rather expect > > Output: > False > than a failure message in this case. > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| HELP! fileExist function always return 'FALSE' | VB Script | |||
| RegEx to return False if input is invalid. | VB Script | |||
| test-path -IsValid ? | PowerShell | |||
| Test-Path isValid parameter | PowerShell | |||
| BUG? (Test-Path $path -IsValid) and empty $path | PowerShell | |||