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

Vista - List only directories with numbers

Reply
 
Old 04-17-2009   #1 (permalink)
Habskilla


 
 

List only directories with numbers

I'm trying to list only directories that match this pattern:

v[1-9]*

The first letter is v. The next char is a number followed by any number of
chars.



My System SpecsSystem Spec
Old 04-17-2009   #2 (permalink)
mr_unreliable


 
 

Re: List only directories with numbers

Habskilla wrote:
Quote:

> I'm trying to list only directories that match this pattern:
>
> v[1-9]*
>
> The first letter is v. The next char is a number followed by any number of
> chars.
>
hi Habskilla,

There are (at least) two obvious choices.

The "brute force" method. Extract the right character
(using the Left function) and test for "v". Then extract
the next character (the mid function would work) and test
for "IsNumeric".

If you want to be a little more sophisticated, (with
bragging rights among the other programmers at your local
brewpub), then read up on the "regexp" class. To use
that, you set up a "pattern" and then compare your
directory (oops, I meant folder name) name with the
pattern.

cheers, jw
____________________________________________________________

You got questions? WE GOT ANSWERS!!! ..(but, no guarantee
the answers will be applicable to the questions)

My System SpecsSystem Spec
Old 04-17-2009   #3 (permalink)
ekkehard.horner


 
 

Re: List only directories with numbers

Habskilla schrieb:
Quote:

> I'm trying to list only directories that match this pattern:
>
> v[1-9]*
>
> The first letter is v. The next char is a number followed by any number of
> chars.
>
>
You could use a Regexp:

Dim aTests : aTests = Array( _
"v1x", "V1X", "v1", "vA", "xv9b" _
)
Dim oRE : Set oRE = New RegExp
oRE.IgnoreCase = True
oRE.Pattern = "^v[1-9].*"
Dim nIdx
For nIdx = 0 To UBound( aTests )
WScript.Echo Right( " " & nIdx, 3 ) _
, CStr( oRE.Test( aTests( nIdx ) ) ) _
& vbTab & "|" & aTests( nIdx ) & "|"
Next

output:

=== matchVNX: RegExp for v[1-9]* ====
0 Wahr |v1x|
1 Wahr |V1X|
2 Wahr |v1|
3 Falsch |vA|
4 Falsch |xv9b|
=== matchVNX: 0 done (00:00:00) =====

The given pattern means:

^ at the start of the string
v has to be exactly one v (the property IgnoreCase will
cause a match for V too)
[1-9] exactly one digit 1,2,..9
.. arbitrary character (except vbLf)
* zero or more of that

In case "v1", .."V9" are to be excluded according to your specs,
change the pattern to "^v[1-9].+" (+ == 1 or more of that)

My System SpecsSystem Spec
Old 04-17-2009   #4 (permalink)
Habskilla


 
 

Re: List only directories with numbers


"ekkehard.horner" <ekkehard.horner@xxxxxx> wrote in message
news:49e8b04d$0$32667$9b4e6d93@xxxxxx-online.net...
Quote:

> Habskilla schrieb:
Quote:

>> I'm trying to list only directories that match this pattern:
>>
>> v[1-9]*
>>
>> The first letter is v. The next char is a number followed by any number
>> of chars.
> You could use a Regexp:
>
> Dim aTests : aTests = Array( _
> "v1x", "V1X", "v1", "vA", "xv9b" _
> )
> Dim oRE : Set oRE = New RegExp
> oRE.IgnoreCase = True
> oRE.Pattern = "^v[1-9].*"
> Dim nIdx
> For nIdx = 0 To UBound( aTests )
> WScript.Echo Right( " " & nIdx, 3 ) _
> , CStr( oRE.Test( aTests( nIdx ) ) ) _
> & vbTab & "|" & aTests( nIdx ) & "|"
> Next
>
> output:
>
> === matchVNX: RegExp for v[1-9]* ====
> 0 Wahr |v1x|
> 1 Wahr |V1X|
> 2 Wahr |v1|
> 3 Falsch |vA|
> 4 Falsch |xv9b|
> === matchVNX: 0 done (00:00:00) =====
>
> The given pattern means:
>
> ^ at the start of the string
> v has to be exactly one v (the property IgnoreCase will
> cause a match for V too)
> [1-9] exactly one digit 1,2,..9
> . arbitrary character (except vbLf)
> * zero or more of that
>
> In case "v1", .."V9" are to be excluded according to your specs,
> change the pattern to "^v[1-9].+" (+ == 1 or more of that)
>
Thanks, this will get me going.


My System SpecsSystem Spec
Old 04-18-2009   #5 (permalink)
mr_unreliable


 
 

oops

mr_unreliable wrote:
Quote:

> ... Extract the right character
> (using the Left function) and test for "v".
That should have read:

Extract the LEFT char using the LEFT function.

cheers, jw
My System SpecsSystem Spec
Old 04-18-2009   #6 (permalink)
Todd Vargo


 
 

Re: oops

mr_unreliable wrote:
Quote:

> mr_unreliable wrote:
Quote:

> > ... Extract the right character
> > (using the Left function) and test for "v".
>
> That should have read:
>
> Extract the LEFT char using the LEFT function.
I took it to mean 'extract the correct character' so I let it pass.

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Local folder list, mail numbers Vista mail
List FTP Directories PowerShell
Optimizing PS Script to List directories PowerShell
VLK Numbers Vista General
SKU numbers 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