![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | 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) | ||||||||||||
| Guest | 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
| ||||||||||||
My System Specs![]() | |||||||||||||
| | #3 (permalink) | ||||||||||||
| Guest | 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
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) | ||||||||||||||||||||||||
| Guest | 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
| ||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| test-path -IsValid ? | Ray | PowerShell | 2 | 04-03-2008 06:48 AM |
| Test-Path isValid parameter | Shay Levi | PowerShell | 5 | 09-20-2007 09:53 AM |
| Get-Location return for UNC path | ~Clint | PowerShell | 2 | 12-05-2006 05:34 PM |
| how to test for a program in my path? | =?Utf-8?B?R2lsIE5vdmFr?= | PowerShell | 2 | 09-26-2006 05:12 PM |
| BUG? (Test-Path $path -IsValid) and empty $path | =?Utf-8?B?Um9tYW4gS3V6bWlu?= | PowerShell | 1 | 08-28-2006 12:10 PM |