Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Test-Path isValid parameter

Reply
 
Old 09-19-2007   #1 (permalink)
Shay Levi


 
 

Test-Path isValid parameter

From the help file

-isValid <SwitchParameter>
Determines whether the syntax of the path is correct, regardless of whether
the elements of the path exist. Returns TRUE if the
path syntax is valid; FALSE if it is not.


Should I rely on Test-Path's -isValid parameter ???


PS C:\Scripts> Test-Path c:\ -isValid
True

PS C:\Scripts> Test-Path c:\]] -isValid
True

PS C:\Scripts> Test-Path c:\\\ -isValid
True

PS C:\Scripts> Test-Path \\\ -isValid
False

PS C:\Scripts> Test-Path z\\\ -isValid
True

PS C:\Scripts> Test-Path z\\\// -isValid
True

PS C:\Scripts> Test-Path shay-levi -isValid
True



Shay
http://scriptolog.blogspot.com



My System SpecsSystem Spec
Old 09-19-2007   #2 (permalink)
Oisin Grehan


 
 

Re: Test-Path isValid parameter

On Sep 19, 6:26 pm, Shay Levi <n...@xxxxxx> wrote:
Quote:

> From the help file
>
> -isValid <SwitchParameter>
> Determines whether the syntax of the path is correct, regardless of whether
> the elements of the path exist. Returns TRUE if the
> path syntax is valid; FALSE if it is not.
>
> Should I rely on Test-Path's -isValid parameter ???
>
> PS C:\Scripts> Test-Path c:\ -isValid
> True
>
> PS C:\Scripts> Test-Path c:\]] -isValid
> True
>
> PS C:\Scripts> Test-Path c:\\\ -isValid
> True
>
> PS C:\Scripts> Test-Path \\\ -isValid
> False
>
> PS C:\Scripts> Test-Path z\\\ -isValid
> True
>
> PS C:\Scripts> Test-Path z\\\// -isValid
> True
>
> PS C:\Scripts> Test-Path shay-levi -isValid
> True
>
> Shayhttp://scriptolog.blogspot.com
should you rely on it for what, exactly? it's about syntactic
validity, not exists etc.

- Oisin

My System SpecsSystem Spec
Old 09-20-2007   #3 (permalink)
Kiron


 
 

Re: Test-Path isValid parameter

The -isValid switch parameter checks for the presence of 'invalid' filename
characters...
" * : < > ? |
....if present it returns $false.

32..255|?{!(test-path "$([char]$_)" -isValid)}|%{[char]$_}

Could be used to ensure the validity of randomly generated file names for
example.

--
Kiron

My System SpecsSystem Spec
Old 09-20-2007   #4 (permalink)
kirk


 
 

Re: Test-Path isValid parameter

On Sep 20, 5:07 pm, "Kiron" <Ki...@xxxxxx> wrote:
Quote:

> The -isValid switch parameter checks for the presence of 'invalid' filename
> characters...
> " * : < > ? |
> ...if present it returns $false.
>
> 32..255|?{!(test-path "$([char]$_)" -isValid)}|%{[char]$_}
>
> Could be used to ensure the validity of randomly generated file names for
> example.
Hi Kiron,

I agree, although note that if you use
[System.IO.Path]::GetRandomFileName() you get a nice random filename
that contains only safe characters:

http://pageofwords.com/blog/default.aspx?page=admin

Kirk

My System SpecsSystem Spec
Old 09-20-2007   #5 (permalink)
Shay Levi


 
 

Re: Test-Path isValid parameter

Thank you guys.

Shay
http://scriptolog.blogspot.com


Quote:

> From the help file
>
> -isValid <SwitchParameter>
> Determines whether the syntax of the path is correct, regardless
> of whether
> the elements of the path exist. Returns TRUE if the
> path syntax is valid; FALSE if it is not.
> Should I rely on Test-Path's -isValid parameter ???
>
> PS C:\Scripts> Test-Path c:\ -isValid
> True
> PS C:\Scripts> Test-Path c:\]] -isValid
> True
> PS C:\Scripts> Test-Path c:\\\ -isValid
> True
> PS C:\Scripts> Test-Path \\\ -isValid
> False
> PS C:\Scripts> Test-Path z\\\ -isValid
> True
> PS C:\Scripts> Test-Path z\\\// -isValid
> True
> PS C:\Scripts> Test-Path shay-levi -isValid
> True
> Shay
> http://scriptolog.blogspot.com

My System SpecsSystem Spec
Old 09-20-2007   #6 (permalink)
Kiron


 
 

Re: Test-Path isValid parameter

Thanks Kirk. Good tip.

--
Kiron

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
test-path -IsValid ? PowerShell
test for executable on path PowerShell
Test-Path '' -IsValid does not return False but fails. Is this OK? PowerShell
how to test for a program in my path? PowerShell
BUG? (Test-Path $path -IsValid) and empty $path PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46