![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| Guest | BUG? (Test-Path $path -IsValid) and empty $path I would like to check if $path is a syntactically valid path using Test-Path with -IsValid switch , i.e.: PS> $path = '' # why not? PS> if (!(Test-Path $path -IsValid)) {Write-Warning "Path <$path> is invalid"} Surprisingly Test-Path fails and instead of expected WARNING: Path <> is invalid I get very disappointing: Test-Path : Cannot bind argument to parameter 'Path' because it is an empty string. The problem is not just a misleading message, but something worse - my code was not executed as it was designed for an invalid path. Note: I can’t even suppress this failure: PS> Test-Path '' -ea SilentlyContinue Test-Path : Cannot bind argument to parameter 'Path' because it is an empty string. Then, if -Path is an empty string, there are even more oddities: PS> Test-Path '' -xxx Instead of more likely expected error Test-Path : A parameter cannot be found that matches parameter name 'xxx'. I get again Test-Path : Cannot bind argument to parameter 'Path' because it is an empty string. All this does not look good, IMO. Any ideas? Am I missing something? -- Thanks, Roman |
My System Specs![]() |
| | #2 (permalink) |
| Guest | Re: BUG? (Test-Path $path -IsValid) and empty $path This does look like a bug, and happening in the parameter binding code, i believe. Also, unfortunately is seems that all of the *path cmdlets suffer from this. There is a way around this with a trap if ( ! $( trap { continue }; test-path $path -isvalid)) { Write-Warning "Path <$path> is invalid } I haven't looked at the code, but my guess is that the ErrorAction parameter value is not applied to the parameter binding process, thus you don't get the ErrorAction behavior that you specified. jim -- James Truher[MSFT] Program Manager - Windows PowerShell Microsoft Corporation This posting is provided "AS IS" with no warranties, no confers rights. Visit the Windows PowerShell Team blog at: http://blogs.msdn.com/PowerShell Visit the Windows PowerShell ScriptCenter at: http://www.microsoft.com/technet/scr.../hubs/msh.mspx "Roman Kuzmin" <RomanKuzmin@discussions.microsoft.com> wrote in message news:E6A307BF-CCE8-4306-844E-4E724DF61EAD@microsoft.com... >I would like to check if $path is a syntactically valid path using >Test-Path > with -IsValid switch , i.e.: > > PS> $path = '' # why not? > PS> if (!(Test-Path $path -IsValid)) {Write-Warning "Path <$path> is > invalid"} > > Surprisingly Test-Path fails and instead of expected > > WARNING: Path <> is invalid > > I get very disappointing: > > Test-Path : Cannot bind argument to parameter 'Path' because it is an > empty string. > > The problem is not just a misleading message, but something worse - my > code > was not executed as it was designed for an invalid path. > > Note: I can't even suppress this failure: > > PS> Test-Path '' -ea SilentlyContinue > Test-Path : Cannot bind argument to parameter 'Path' because it is an > empty string. > > Then, if -Path is an empty string, there are even more oddities: > > PS> Test-Path '' -xxx > > Instead of more likely expected error > > Test-Path : A parameter cannot be found that matches parameter name > 'xxx'. > > I get again > > Test-Path : Cannot bind argument to parameter 'Path' because it is an > empty string. > > All this does not look good, IMO. > Any ideas? Am I missing something? > > -- > Thanks, > Roman |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| test-path -IsValid ? | PowerShell | |||
| Test-Path '' -IsValid does not return False but fails. Is this OK? | PowerShell | |||
| Test-Path isValid parameter | PowerShell | |||
| BUG/ANNOYANCE: PoSH autocompletes the full path rather than a minimal path | PowerShell | |||