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 - Trying to understand inconsistency.

Reply
 
Old 02-22-2007   #1 (permalink)
Jason


 
 

Trying to understand inconsistency.

I can see where
(dir | where {$_.name -like '*.exe'}).count
works the same as
(dir *.exe).count

But why does this work:
(dir -Recurse | where {$_.name -like '*.exe'}).count
But this does not:
(dir -recurse *.exe).count

There's probably a simple answer. Thanks in advance.

My System SpecsSystem Spec
Old 02-22-2007   #2 (permalink)
RichS


 
 

RE: Trying to understand inconsistency.

This seems to work

(dir -recurse -filter *.txt).count

Not 100% sure as to the why but this part of the help file for the recurse
parameter

Recurse works only when the path points to a container that has child
items, such as C:\Windows or C:\Windows\*, and not when it points to items
that do not have child items, such as C:\Windows\*.exe.

I think its saying that the (dir -recurse *.exe).count version is not able
to recurse through the child folders because its not recognising the path it
need to use
--
Richard Siddaway
Please note that all scripts are supplied "as is" and with no warranty
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk


"Jason" wrote:

> I can see where
> (dir | where {$_.name -like '*.exe'}).count
> works the same as
> (dir *.exe).count
>
> But why does this work:
> (dir -Recurse | where {$_.name -like '*.exe'}).count
> But this does not:
> (dir -recurse *.exe).count
>
> There's probably a simple answer. Thanks in advance.

My System SpecsSystem Spec
Old 02-23-2007   #3 (permalink)
Keith Hill


 
 

Re: Trying to understand inconsistency.

"Jason" <Jason@discussions.microsoft.com> wrote in message
news:EC8DD0F9-F449-45E8-AA3E-7B6E95DBC920@microsoft.com...
>I can see where
> (dir | where {$_.name -like '*.exe'}).count
> works the same as
> (dir *.exe).count
>
> But why does this work:
> (dir -Recurse | where {$_.name -like '*.exe'}).count
> But this does not:
> (dir -recurse *.exe).count
>
> There's probably a simple answer. Thanks in advance.


Try this:

@(dir -recurse *.exe).count

My guess is that your dir command is only returning a single FileInfo
object. System.IO.FileInfo doesn't have a "Count" property. Fortunately
there is a simple construct in PowerShell called an array subexpression that
you can use to tell PowerShell to create an array with a single element *if*
the inner expression evaluates to a single/scalar value. If the expression
evaluates to an array then the array subexpression syntax is no different
than just using naked parens (grouping) i.e. it does *not* wrap that array
in yet another array.

--
Keith

My System SpecsSystem Spec
Old 02-24-2007   #4 (permalink)
mikes.net


 
 

Re: Trying to understand inconsistency.

While what you say is completely true and good to remember, it is not
the whole issue in this case, at least I don't think so. I think what
he was missing was to use a "." with gci. Gci has some quirks which
are easier to just learn than try to explain. Many problems with gci
can be solved by remembering this pattern:

gci . -recurse *.exe | % { Next-Cmdlet -path $_.fullname }

HTH

Mike

> Try this:
>
> @(dir -recurse *.exe).count
>
> My guess is that your dir command is only returning a single FileInfo
> object. System.IO.FileInfo doesn't have a "Count" property. Fortunately
> there is a simple construct in PowerShell called an array subexpression that
> you can use to tell PowerShell to create an array with a single element *if*
> the inner expression evaluates to a single/scalar value. If the expression
> evaluates to an array then the array subexpression syntax is no different
> than just using naked parens (grouping) i.e. it does *not* wrap that array
> in yet another array.
>
> --
> Keith



My System SpecsSystem Spec
Old 02-24-2007   #5 (permalink)
Keith Hill


 
 

Re: Trying to understand inconsistency.

"mikes.net" <michael.net@gmail.com> wrote in message
news:1172326924.460450.164130@s48g2000cws.googlegroups.com...
> While what you say is completely true and good to remember, it is not
> the whole issue in this case, at least I don't think so. I think what
> he was missing was to use a "." with gci. Gci has some quirks which
> are easier to just learn than try to explain. Many problems with gci
> can be solved by remembering this pattern:
>
> gci . -recurse *.exe | % { Next-Cmdlet -path $_.fullname }
>


Yeah you are absolutely correct.

--
Keith

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Vista Seach inconsistency Vista General
VirtualStore inconsistency? Vista General
File Type Ordering Inconsistency Vista file management
I dun understand. Vista General


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