Home All Groups Group Topic Archive Search About

filesystem.getfiles question

Author
13 Feb 2006 1:03 PM
al jones
I'm using filesystem.getfiles - and so far it's working correctly *however*
I'd sure like to be able to pass it, as the last parameter, the extensions
(plural) for which I'm looking.

I assumed that "*.exe, *.dll" for example would work but it seems to not
like that syntax.  Would someone correct my misinformation and give me a
way to pass more than a single pattern to that last parameter??

Thanks //al

Author
13 Feb 2006 2:07 PM
Armin Zingler
"al jones" <alfredmjo***@shotmail.com> schrieb
> I'm using filesystem.getfiles - and so far it's working correctly
> *however* I'd sure like to be able to pass it, as the last
> parameter, the extensions (plural) for which I'm looking.
>
> I assumed that "*.exe, *.dll" for example would work but it seems to
> not like that syntax.  Would someone correct my misinformation and
> give me a way to pass more than a single pattern to that last
> parameter??


It is not possible to pass multiple extensions. Get all files and filter
them by extension in a loop.

I don't see the relation to the VB.Net language. Maybe one of the Framework
groups is the better place to ask:

microsoft.public.dotnet.framework.*

You'll benefit from the none-VB'ers, too.


Armin
Author
13 Feb 2006 9:45 PM
CMM
"Armin Zingler" <az.nospam@freenet.de> wrote in message
> microsoft.public.dotnet.framework.*
> You'll benefit from the none-VB'ers, too.

Sorta ironic you say this... considering the feature he seeks AFAIK is only
available in VB (2005) via
My.Computer.FileSystem.GetFiles(...)

--
-C. Moya
www.cmoya.com
Author
14 Feb 2006 6:05 PM
Armin Zingler
"CMM" <cmm@nospam.com> schrieb
> "Armin Zingler" <az.nospam@freenet.de> wrote in message
> > microsoft.public.dotnet.framework.*
> > You'll benefit from the none-VB'ers, too.
>
> Sorta ironic you say this... considering the feature he seeks AFAIK
> is only available in VB (2005) via
> My.Computer.FileSystem.GetFiles(...)

They'd better spend the time putting it into the framework... ;-)


Armin
Author
13 Feb 2006 9:40 PM
CMM
If you're using VB2005,
My.Computer.FileSystem.GetFiles(...)
Allows you to specify multiple patterns.

--
-C. Moya
www.cmoya.com
Author
13 Feb 2006 9:53 PM
CMM
On the other hand, if you're using VB2003, then you can't use
My.Computer.FileSystem.GetFiles().

In which case you can either:

1) Get all the files (*.*) and loop through them yourself recursively using
VB's Like operator (very handly little known comparison operator).

For Each file As String in filesAry
    For Each pattern As String in patternsAry
        If File.GetFileName(file) Like pattern Then
            'do something
        End If
    Next pattern
Next file

2) Call GetFiles multiple times each with a different pattern. I would
actually think #1 above is the faster option.

--
-C. Moya
www.cmoya.com
Show quoteHide quote
"CMM" <cmm@nospam.com> wrote in message
news:%23n6JoYOMGHA.2668@tk2msftngp13.phx.gbl...
> If you're using VB2005,
> My.Computer.FileSystem.GetFiles(...)
> Allows you to specify multiple patterns.
>
> --
> -C. Moya
> www.cmoya.com
>
Author
14 Feb 2006 6:08 PM
Armin Zingler
"CMM" <cmm@nospam.com> schrieb
> On the other hand, if you're using VB2003, then you can't use
> My.Computer.FileSystem.GetFiles().
>
> In which case you can either:
>
> 1) Get all the files (*.*) and loop through them yourself
> recursively using VB's Like operator (very handly little known
> comparison operator).
>
> For Each file As String in filesAry
>    For Each pattern As String in patternsAry
>        If File.GetFileName(file) Like pattern Then

I'd prefer

    select case io.path.getextension.tolower
    case ".exe", ".dll"    'or without dot (never know by heart)
        msgbox "good file"
    case
        msgbox "bad file"
    end seelct

:)


Armin
Author
14 Feb 2006 6:59 PM
CMM
> I'd prefer  ... <snip>

Sure. Though, my method accomodates more complex search patterns akin to a
real search. You might not necessarily just want to search for extensions.

Forward thinking, man. Forward thinking.

--
-C. Moya
www.cmoya.com
Author
14 Feb 2006 2:04 AM
al jones
On Mon, 13 Feb 2006 16:40:44 -0500, CMM wrote:

> If you're using VB2005,
> My.Computer.FileSystem.GetFiles(...)
> Allows you to specify multiple patterns.

I got a chuckle out of your response to Armin - I assumed that getfiles
would be available across the family of languages but you're right I *am*
using vb2005. 

I must be being really dense, though, can you explain how to specify those
multiple patterns?  The tooltip associated with getfiles says that this
item is a ParamArray wildcards() as string.  I've tried "*.exe;*.dll" which
returned nothing and thinking that This should be an array
{"*.exe","*.dll"} which the ide complains about ...

Another response to a similar questions suggests making two passes one for
each extension - which is doable, but the time this takes on a large
directory is long to begin with, doubling or tripling it would be
prohibitive.  Suggestions?

And thanks to both of you //al
Author
14 Feb 2006 3:21 AM
CMM
A "paramarray" means you can specify parameters *inline* for infinity pretty
much
MyProc(param1,param2,param3,param4, ...) You can also pass them as a
singular array if you want. This is how you use the getfiles function:

....

Dim files As ObjectModel.ReadOnlyCollection(Of String) = _
My.Computer.FileSystem.GetFiles("C:\Temp",
FileIO.SearchOption.SearchAllSubDirectories, "*.exe", "*.dll")

or

Dim files2 As ObjectModel.ReadOnlyCollection(Of String) = _
    My.Computer.FileSystem.GetFiles("C:\Temp",
FileIO.SearchOption.SearchAllSubDirectories, New String() {"*.exe",
"*.dll"})


P.S.
ObjectModel.ReadonlyCollection is in the System.Collections namespace.

--
-C. Moya
www.cmoya.com
Show quoteHide quote
"al jones" <alfredmjo***@shotmail.com> wrote in message
news:197l360fl2lz1$.r53jlqua6wtn.dlg@40tude.net...
> On Mon, 13 Feb 2006 16:40:44 -0500, CMM wrote:
>
>> If you're using VB2005,
>> My.Computer.FileSystem.GetFiles(...)
>> Allows you to specify multiple patterns.
>
> I got a chuckle out of your response to Armin - I assumed that getfiles
> would be available across the family of languages but you're right I *am*
> using vb2005.
>
> I must be being really dense, though, can you explain how to specify those
> multiple patterns?  The tooltip associated with getfiles says that this
> item is a ParamArray wildcards() as string.  I've tried "*.exe;*.dll"
> which
> returned nothing and thinking that This should be an array
> {"*.exe","*.dll"} which the ide complains about ...
>
> Another response to a similar questions suggests making two passes one for
> each extension - which is doable, but the time this takes on a large
> directory is long to begin with, doubling or tripling it would be
> prohibitive.  Suggestions?
>
> And thanks to both of you //al
Author
14 Feb 2006 3:23 PM
Galen Somerville
I think the VB.net developers had to go to school to learn how to make
things as convoluted as possible.

GalenS

Show quoteHide quote
"CMM" <cmm@nospam.com> wrote in message
news:erlLxWRMGHA.3896@TK2MSFTNGP15.phx.gbl...
>A "paramarray" means you can specify parameters *inline* for infinity
>pretty much
> MyProc(param1,param2,param3,param4, ...) You can also pass them as a
> singular array if you want. This is how you use the getfiles function:
>
> ...
>
> Dim files As ObjectModel.ReadOnlyCollection(Of String) = _
> My.Computer.FileSystem.GetFiles("C:\Temp",
> FileIO.SearchOption.SearchAllSubDirectories, "*.exe", "*.dll")
>
> or
>
> Dim files2 As ObjectModel.ReadOnlyCollection(Of String) = _
>    My.Computer.FileSystem.GetFiles("C:\Temp",
> FileIO.SearchOption.SearchAllSubDirectories, New String() {"*.exe",
> "*.dll"})
>
>
> P.S.
> ObjectModel.ReadonlyCollection is in the System.Collections namespace.
>
> --
> -C. Moya
> www.cmoya.com
> "al jones" <alfredmjo***@shotmail.com> wrote in message
> news:197l360fl2lz1$.r53jlqua6wtn.dlg@40tude.net...
>> On Mon, 13 Feb 2006 16:40:44 -0500, CMM wrote:
>>
>>> If you're using VB2005,
>>> My.Computer.FileSystem.GetFiles(...)
>>> Allows you to specify multiple patterns.
>>
>> I got a chuckle out of your response to Armin - I assumed that getfiles
>> would be available across the family of languages but you're right I *am*
>> using vb2005.
>>
>> I must be being really dense, though, can you explain how to specify
>> those
>> multiple patterns?  The tooltip associated with getfiles says that this
>> item is a ParamArray wildcards() as string.  I've tried "*.exe;*.dll"
>> which
>> returned nothing and thinking that This should be an array
>> {"*.exe","*.dll"} which the ide complains about ...
>>
>> Another response to a similar questions suggests making two passes one
>> for
>> each extension - which is doable, but the time this takes on a large
>> directory is long to begin with, doubling or tripling it would be
>> prohibitive.  Suggestions?
>>
>> And thanks to both of you //al
>
>
Author
14 Feb 2006 4:25 PM
CMM
I don't see how.
Doesn't get much simpler than usage of that function... and intellisense
guides you the whole way... though I guess it does look wordy.

--
-C. Moya
www.cmoya.com