Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

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.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

where-object

Closed Thread
 
Thread Tools Display Modes
Old 02-07-2007   #1 (permalink)
Corinne
Guest


 

where-object

Hi everyone,

I am trying to pull a list of all the files in a directory that end with
".car"

my where-object syntax fails ont he following:

where-object {$_name -match "*.CAR*"}

Where is th problem? Can you help?

Thank you

Corinne


Old 02-07-2007   #2 (permalink)
RichS
Guest


 

RE: where-object

-match is used to match against a regular expression - see

help about_comparison_operators
and
help about_regular_expression

The easiest way to acheive what you want is to use

where{$_.name -like "*.CAR*"}

or to use the filter option on get-childitem

get-childitem -filter *.car*

--
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


"Corinne" wrote:

> Hi everyone,
>
> I am trying to pull a list of all the files in a directory that end with
> ".car"
>
> my where-object syntax fails ont he following:
>
> where-object {$_name -match "*.CAR*"}
>
> Where is th problem? Can you help?
>
> Thank you
>
> Corinne
>
>
>

Old 02-07-2007   #3 (permalink)
Bruno Guerpillon
Guest


 

Re: where-object

Hi Corinne

I guesst you forget the "." after $_

Try this :

Get-ChildItem | Where-Object -FilterScript { $_.name -like '*.car'}

Regards

Bruno


"Corinne" <clofts@shepherd-neame.co.uk> a écrit dans le message de news:
OHqxzCrSHHA.1036@TK2MSFTNGP03.phx.gbl...
> Hi everyone,
>
> I am trying to pull a list of all the files in a directory that end with
> ".car"
>
> my where-object syntax fails ont he following:
>
> where-object {$_name -match "*.CAR*"}
>
> Where is th problem? Can you help?
>
> Thank you
>
> Corinne
>



Old 02-07-2007   #4 (permalink)
Corinne
Guest


 

Re: where-object

Thank you Richard!


"RichS" <RichS@discussions.microsoft.com> wrote in message
news:2B6D4704-A252-4F2E-A24F-C2ED34DF090B@microsoft.com...
> -match is used to match against a regular expression - see
>
> help about_comparison_operators
> and
> help about_regular_expression
>
> The easiest way to acheive what you want is to use
>
> where{$_.name -like "*.CAR*"}
>
> or to use the filter option on get-childitem
>
> get-childitem -filter *.car*
>
> --
> 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
>
>
> "Corinne" wrote:
>
>> Hi everyone,
>>
>> I am trying to pull a list of all the files in a directory that end with
>> ".car"
>>
>> my where-object syntax fails ont he following:
>>
>> where-object {$_name -match "*.CAR*"}
>>
>> Where is th problem? Can you help?
>>
>> Thank you
>>
>> Corinne
>>
>>
>>



Old 02-07-2007   #5 (permalink)
Corinne
Guest


 

Re: where-object

Merci Bruno!


"Bruno Guerpillon" <toto@toto.fr> wrote in message
news:45c9d115$0$23926$426a34cc@news.free.fr...
> Hi Corinne
>
> I guesst you forget the "." after $_
>
> Try this :
>
> Get-ChildItem | Where-Object -FilterScript { $_.name -like '*.car'}
>
> Regards
>
> Bruno
>
>
> "Corinne" <clofts@shepherd-neame.co.uk> a écrit dans le message de news:
> OHqxzCrSHHA.1036@TK2MSFTNGP03.phx.gbl...
>> Hi everyone,
>>
>> I am trying to pull a list of all the files in a directory that end with
>> ".car"
>>
>> my where-object syntax fails ont he following:
>>
>> where-object {$_name -match "*.CAR*"}
>>
>> Where is th problem? Can you help?
>>
>> Thank you
>>
>> Corinne
>>

>
>



Old 02-07-2007   #6 (permalink)
Keith Hill
Guest


 

Re: where-object

"Corinne" <clofts@shepherd-neame.co.uk> wrote in message
news:OHqxzCrSHHA.1036@TK2MSFTNGP03.phx.gbl...
> Hi everyone,
>
> I am trying to pull a list of all the files in a directory that end with
> ".car"
>
> my where-object syntax fails ont he following:
>
> where-object {$_name -match "*.CAR*"}
>
> Where is th problem? Can you help?


And if you really want to test to see if the filename "ends" with .car use
"\.car$" as your regular expression otherwise just using ".car*" would match
the following also:

fcar
f.car.txt

--
Keith

Old 02-07-2007   #7 (permalink)
William Stacey [C# MVP]
Guest


 

Re: where-object

You know what they say. When you have a problem you need regex for...now
you have two problems...

--
William Stacey [C# MVP]
PCR concurrency library: www.codeplex.com/pcr
PSH Scripts Project www.codeplex.com/psobject


"Keith Hill" <r_keith_hill@mailhot.nospamIdotcom> wrote in message
news:FA9B92C7-220A-4559-A6DE-9746CEF5A901@microsoft.com...
| "Corinne" <clofts@shepherd-neame.co.uk> wrote in message
| news:OHqxzCrSHHA.1036@TK2MSFTNGP03.phx.gbl...
| > Hi everyone,
| >
| > I am trying to pull a list of all the files in a directory that end with
| > ".car"
| >
| > my where-object syntax fails ont he following:
| >
| > where-object {$_name -match "*.CAR*"}
| >
| > Where is th problem? Can you help?
|
| And if you really want to test to see if the filename "ends" with .car use
| "\.car$" as your regular expression otherwise just using ".car*" would
match
| the following also:
|
| fcar
| f.car.txt
|
| --
| Keith
|


Old 02-07-2007   #8 (permalink)
Keith Hill
Guest


 

Re: where-object

"William Stacey [C# MVP]" <william.stacey@gmail.com> wrote in message
news:eObDXBtSHHA.3500@TK2MSFTNGP05.phx.gbl...
> You know what they say. When you have a problem you need regex for...now
> you have two problems...


Heh, isn't that the truth. :-) There's a lot of power in regex's but they
aren't always easy to construct properly. It's especially dangerous
extrapolating the PowerShell wildcard/globbing syntax to regex's. Best
thing to do is create some sample input and make sure your regex is matching
and, just as important, not matching as you would expect.

I've been a casual user of regex's over the years which is a somewhat
dangerous level of knowledge to have. Right now I'm reading through the
O'Reilly Mastering Regular Expressions book (3rd edition). So far I'd have
to say that it is a good book. Hopefully in the 4th edition they will give
..NET some more love with more PowerShell and fewer Perl examples. :-)

--
Keith

Old 02-08-2007   #9 (permalink)
/\/\o\/\/ [MVP]
Guest


 

Re: where-object

> WHEN you have a problem you need regex for...

Get-ChildItem | Where {$_.extension -eq '.car'}

ls *.car

Greetings /\/\o\/\/

"Keith Hill" wrote:

> "William Stacey [C# MVP]" <william.stacey@gmail.com> wrote in message
> news:eObDXBtSHHA.3500@TK2MSFTNGP05.phx.gbl...
> > You know what they say. When you have a problem you need regex for...now
> > you have two problems...

>
> Heh, isn't that the truth. :-) There's a lot of power in regex's but they
> aren't always easy to construct properly. It's especially dangerous
> extrapolating the PowerShell wildcard/globbing syntax to regex's. Best
> thing to do is create some sample input and make sure your regex is matching
> and, just as important, not matching as you would expect.
>
> I've been a casual user of regex's over the years which is a somewhat
> dangerous level of knowledge to have. Right now I'm reading through the
> O'Reilly Mastering Regular Expressions book (3rd edition). So far I'd have
> to say that it is a good book. Hopefully in the 4th edition they will give
> .NET some more love with more PowerShell and fewer Perl examples. :-)
>
> --
> Keith
>

Old 02-08-2007   #10 (permalink)
Lee Holmes [MSFT]
Guest


 

Re: where-object

One option for that is the PowerShell quick reference. It has PowerShell
examples for all of the possible regex bits.

--
Lee Holmes [MSFT]
Windows PowerShell Development
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.

"Keith Hill" <r_keith_hill@mailhot.nospamIdotcom> wrote in message
news:4BEB9661-0377-4183-B2A4-2DBE7C0A1803@microsoft.com...
> "William Stacey [C# MVP]" <william.stacey@gmail.com> wrote in message
> news:eObDXBtSHHA.3500@TK2MSFTNGP05.phx.gbl...
>> You know what they say. When you have a problem you need regex for...now
>> you have two problems...

>
> Heh, isn't that the truth. :-) There's a lot of power in regex's but
> they aren't always easy to construct properly. It's especially dangerous
> extrapolating the PowerShell wildcard/globbing syntax to regex's. Best
> thing to do is create some sample input and make sure your regex is
> matching and, just as important, not matching as you would expect.
>
> I've been a casual user of regex's over the years which is a somewhat
> dangerous level of knowledge to have. Right now I'm reading through the
> O'Reilly Mastering Regular Expressions book (3rd edition). So far I'd
> have to say that it is a good book. Hopefully in the 4th edition they
> will give .NET some more love with more PowerShell and fewer Perl
> examples. :-)
>
> --
> Keith



Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
datalist -- Object reference not set to an instance of an object. Deere .NET General 0 1 Week Ago 09:09 AM
Compare-Object and Get the name of object/File? akcorr PowerShell 5 06-19-2008 05:15 AM
Testing object arrays using Compare-Object and -contains Alex K. Angelopoulos [MVP] PowerShell 2 08-31-2006 05:57 PM
Adding canonical aliases for Compare-Object, Measure-Object, New-Object Alex K. Angelopoulos [MVP] PowerShell 2 05-26-2006 07:58 AM








Vistax64.com 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 2005-2008

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 47 48 49 50