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 - dir -recurse | where { $_.FullName -match "[^ASP]" }

Reply
 
Old 05-26-2008   #1 (permalink)
Dreamlusion


 
 

dir -recurse | where { $_.FullName -match "[^ASP]" }

Hi there,

I'm trying to run this in the C:\Windows\Microsoft.NET directory, but
it does not exclude the files containing ASP.. Is the regex wrong or
does this have to do with the quotes?

Regards

My System SpecsSystem Spec
Old 05-26-2008   #2 (permalink)
Hal Rottenberg


 
 

Re: dir -recurse | where { $_.FullName -match "[^ASP]" }

Dreamlusion wrote:
Quote:

> I'm trying to run this in the C:\Windows\Microsoft.NET directory, but
> it does not exclude the files containing ASP.. Is the regex wrong or
> does this have to do with the quotes?
Try the -notmatch operator and drop the caret. As to the question of whether
your regex is wrong, that's a difficult question. Is any regex "wrong"? I'd
like to think that all regular expressions have a right to live. Who are we to
judge them? Don't answer that.

dir -r | ? { $_.name -notmatch "asp" }

That will give you all filenames which do not contain the string "asp". When
you put "[ASP]", that matches any string which contains the letters "A", "S", or
"P"--possibly a much wider set than you intended.


--
Author, Tech Prosaic blog (http://halr9000.com)
Webmaster, Psi (http://psi-im.org)
Community Director, PowerShellCommunity.org
Co-host, PowerScripting Podcast (http://powerscripting.net)
My System SpecsSystem Spec
Old 05-26-2008   #3 (permalink)
Brandon [MVP]


 
 

Re: dir -recurse | where { $_.FullName -match "[^ASP]" }

IMO... I think testing the file extension would be better here as it is
possible a file could have asp in the name.

dir -r | ? { $_.extension-notmatch "asp" }


"Hal Rottenberg" <hal@xxxxxx> wrote in message
news:uhsSaC5vIHA.4912@xxxxxx
Quote:

> Dreamlusion wrote:
Quote:

>> I'm trying to run this in the C:\Windows\Microsoft.NET directory, but
>> it does not exclude the files containing ASP.. Is the regex wrong or
>> does this have to do with the quotes?
>
> Try the -notmatch operator and drop the caret. As to the question of
> whether your regex is wrong, that's a difficult question. Is any regex
> "wrong"? I'd like to think that all regular expressions have a right to
> live. Who are we to judge them? Don't answer that.
>
> dir -r | ? { $_.name -notmatch "asp" }
>
> That will give you all filenames which do not contain the string "asp".
> When you put "[ASP]", that matches any string which contains the letters
> "A", "S", or "P"--possibly a much wider set than you intended.
>
>
> --
> Author, Tech Prosaic blog (http://halr9000.com)
> Webmaster, Psi (http://psi-im.org)
> Community Director, PowerShellCommunity.org
> Co-host, PowerScripting Podcast (http://powerscripting.net)
My System SpecsSystem Spec
Old 05-26-2008   #4 (permalink)
Dreamlusion


 
 

Re: dir -recurse | where { $_.FullName -match "[^ASP]" }

On May 27, 4:08*am, "Brandon [MVP]" <tshell.m...@xxxxxx> wrote:
Quote:

> IMO... I think testing the file extension would be better here as it is
> possible a file could have asp in the name.
>
> dir -r | ? { $_.extension-notmatch "asp" }
>
Brandon,

My intension was to exclude an alphanumeric sequence (in this case
ASP) from the full path name to test how the match operator works, but
I wasn't clear from the beginning. Thank you very much for your reply.
Quote:
Quote:

> > Try the -notmatch operator and drop the caret. *As to the question of
> > whether your regex is wrong, that's a difficult question. *Is any regex
> > "wrong"? *I'd like to think that all regular expressions have a right to
> > live. *Who are we to judge them? *Don't answer that.
>
Quote:

> > dir -r | ? { $_.name -notmatch "asp" }
>
Quote:

> > That will give you all filenames which do not contain the string "asp".
> > When you put "[ASP]", that matches any string which contains the letters
> > "A", "S", or "P"--possibly a much wider set than you intended.
Hal that was exactly what I was looking for. Thank you :-)
My System SpecsSystem Spec
Old 05-27-2008   #5 (permalink)
Shay Levi


 
 

Re: dir -recurse | where { $_.FullName -match "[^ASP]" }


It can be done without a regex:

dir C:\Windows\Microsoft.NET -Exclude *asp*


---
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> On May 27, 4:08 am, "Brandon [MVP]" <tshell.m...@xxxxxx> wrote:
>
Quote:

>> IMO... I think testing the file extension would be better here as it
>> is possible a file could have asp in the name.
>>
>> dir -r | ? { $_.extension-notmatch "asp" }
>>
> Brandon,
>
> My intension was to exclude an alphanumeric sequence (in this case
> ASP) from the full path name to test how the match operator works, but
> I wasn't clear from the beginning. Thank you very much for your reply.
>
Quote:
Quote:

>>> Try the -notmatch operator and drop the caret. As to the question
>>> of whether your regex is wrong, that's a difficult question. Is any
>>> regex "wrong"? I'd like to think that all regular expressions have
>>> a right to live. Who are we to judge them? Don't answer that.
>>>
>>> dir -r | ? { $_.name -notmatch "asp" }
>>>
>>> That will give you all filenames which do not contain the string
>>> "asp". When you put "[ASP]", that matches any string which contains
>>> the letters "A", "S", or "P"--possibly a much wider set than you
>>> intended.
>>>
> Hal that was exactly what I was looking for. Thank you :-)
>

My System SpecsSystem Spec
Old 05-27-2008   #6 (permalink)
Cédric Rup


 
 

Re: dir -recurse | where { $_.FullName -match "[^ASP]" }


I think [^ASP] matches only one character strings that are neither "A" nor
"S" and "P" ;o)
Regex are powerfull but hard to write correctly !
Here the good answer is : do it another way, just as told before...

"Shay Levi" wrote:
Quote:

>
> It can be done without a regex:
>
> dir C:\Windows\Microsoft.NET -Exclude *asp*
>
>
> ---
> Shay Levi
> $cript Fanatic
> http://scriptolog.blogspot.com
>
Quote:

> > On May 27, 4:08 am, "Brandon [MVP]" <tshell.m...@xxxxxx> wrote:
> >
Quote:

> >> IMO... I think testing the file extension would be better here as it
> >> is possible a file could have asp in the name.
> >>
> >> dir -r | ? { $_.extension-notmatch "asp" }
> >>
> > Brandon,
> >
> > My intension was to exclude an alphanumeric sequence (in this case
> > ASP) from the full path name to test how the match operator works, but
> > I wasn't clear from the beginning. Thank you very much for your reply.
> >
Quote:

> >>> Try the -notmatch operator and drop the caret. As to the question
> >>> of whether your regex is wrong, that's a difficult question. Is any
> >>> regex "wrong"? I'd like to think that all regular expressions have
> >>> a right to live. Who are we to judge them? Don't answer that.
> >>>
> >>> dir -r | ? { $_.name -notmatch "asp" }
> >>>
> >>> That will give you all filenames which do not contain the string
> >>> "asp". When you put "[ASP]", that matches any string which contains
> >>> the letters "A", "S", or "P"--possibly a much wider set than you
> >>> intended.
> >>>
> > Hal that was exactly what I was looking for. Thank you :-)
> >
>
>
>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
"BCM Office Addin" Office Application version does not match: Patchalready applied Vista General
"WL Contacts" and "To:" Contact lists do not match Live Mail
Help RocketRaid 2302 Bios wont update - "version match" Vista hardware & devices
"BCM Office Addin" Office Application version does not match: Patchalready applied Vista General
How to make "-match" work silently? 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