![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| | trouble with count / length of array filled from filtered ls hi, i have been scripting PS off and on over the past year or so. the other day i ran across a bug in a script of mine that I'm having trouble understanding. hoping someone can help me get a handle on it. if I do the following interactively in a powershell window: $alist = ls . | where {$_.name -match ".sql$"} $alist.count it works just fine and returns 2 in this case. trying to do the same thing in a script (the main difference ist that I've passed the pattern as a parameter param( [string] $match = "" ) ) i end up with an array that appears to contain an item when I echo it, but shows a count of 0. any idea what could be going wrong here? i borrowed the technique from a different script of mine which has been working fine for months. cheers, Tim Hanson |
My System Specs![]() |
| | #2 (permalink) |
| | Re: trouble with count / length of array filled from filtered ls Hi Tim, the diollar sign is a regex metacharacter (denotes end of line). You need to escape it for -match to succssed: ls . | where {$_.name -match ".sql\$"} You can also get the files without piping to where-object or without using regex at all: ls *.sql --- Shay Levy Windows PowerShell MVP http://blogs.microsoft.co.il/blogs/ScriptFanatic PowerShell Toolbar: http://tinyurl.com/PSToolbar T> hi, T> T> i have been scripting PS off and on over the past year or so. the T> other day i ran across a bug in a script of mine that I'm having T> trouble understanding. hoping someone can help me get a handle on it. T> T> if I do the following interactively in a powershell window: T> $alist = ls . | where {$_.name -match ".sql$"} T> $alist.count T> it works just fine and returns 2 in this case. T> trying to do the same thing in a script (the main difference ist that T> I've passed the pattern as a parameter T> param( T> [string] $match = "" T> ) T> ) i end up with an array that appears to contain an item when I echo T> it, but shows a count of 0. T> T> any idea what could be going wrong here? i borrowed the technique T> from a different script of mine which has been working fine for T> months. T> T> cheers, T> T> Tim Hanson T> |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Trying to figure out how to get object count of unique filtered pr | PowerShell | |||
| Trouble with Array | VB Script | |||
| Newsgroups 'filtered' | Live Mail | |||
| Bug in array.count? | PowerShell | |||
| Junk email does not get filtered. | Vista mail | |||