![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
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.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #2 (permalink) |
| 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 > > > |
| | #3 (permalink) |
| 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 > |
| | #4 (permalink) |
| 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 >> >> >> |
| | #5 (permalink) |
| 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 >> > > |
| | #6 (permalink) |
| 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 |
| | #7 (permalink) |
| 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 | |
| | #8 (permalink) |
| 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 |
| | #9 (permalink) |
| 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 > |
| | #10 (permalink) |
| 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 |
| |
| |
![]() |
| 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 |