Re: vb.net search network drive



On Mar 13, 4:18 pm, "rowe_newsgroups" <rowe_em...@xxxxxxxxx> wrote:
So can anyone help me understand the code:

Dim sFiles() As String = Directory.GetFiles("C:\Windows", "*.exe",
SearchOption.AllDirectories)

I'll try :-)

This statement accomplishes the same thing as my recursively called
ListAllFiles sub if that helps.

First we'll break down what the different parts do:

Directory.GetFiles("C:\Windows", "*.exe", SearchOption.AllDirectories)

This part performs a search the specified directory ("C:\Windows") and
all it's subdirectories (SearchOption.AllDirectories) for any file
that matches the search condition ("*.exe").

Dim sFiles() As String

This declares variable named sFiles that stores an Array (think of a
numbered list) of string values. If you look at the documentation for
Directory.GetFiles, you'll see that it is a function that returns an
array of strings - so what we are doing is matching up the sFiles()
variable with the output of GetFiles.

So now we have a "numbered list" of the names of the files that
GetFiles(...) found, but how do we how many we found? This is where
UBound comes into play. UBound will return number of the last item so
if the array contains 70 items it will return 69 (read on). It returns
69 because an array is zero-based meaning that an array with 10 items
will have items numbered 0,1,2,3,4,5,6,7,8,9 and a UBound of 9. So to
get the actual count of items you need to add 1 to the UBound (or just
use the array's length property)

And know for {0}:

String.Format is a pretty cool function that lets you combine strings.
It works by using placeholders ({n}) that refer to the parameters you
pass it:

For example, String.Format("{0} {1} {2} {1} {0}", "Seth", "says",
"hi") will return a string that says "Seth says hi says Seth". What
it does it just match up the placeholder with the parameter in the
specified position.

Let us know if you need further help!

Thanks,

Seth Rowe

On Mar 13, 3:48 pm, "Computer geek" <JohnTAl...@xxxxxxxxx> wrote:



On Mar 9, 8:55 pm, ShaneO <spc...@xxxxxxxxxxxxxxx> wrote:

ShaneO wrote:

If you are wanting to Count the files, the following code will do
exactly that (watch for line wrapping) -

Dim sFiles() As String = Directory.GetFiles("C:\Windows", "*.exe",
SearchOption.AllDirectories)
MsgBox(String.Format("Number of EXE Files Found = {0}", UBound(sFiles) +
1))

I must apologise to all the new programmers out there. I should also
have pointed out that you'll need the "System.IO" NameSpace in order to
use my code example. (I received an email regarding this!)

NameSpaces are declared at the top of your Code, (above Module or Class
statements) and in this case, it should read -

Imports System.IO

You could also change to a fully qualified version on the first line of
my example like so -

Dim sFiles() As String = System.IO.Directory.GetFiles("C:\Windows",
"*.exe", System.IO.SearchOption.AllDirectories)

but that would create a lot of unnecessary typing.

ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.

OK Let me try this again. I tried posting yesterday but for some
reason it didn't show up. First of all, I want to thank both Seth and
Shane for helping me. I got it to work both ways.. using NameSpace and
a fully qualified version. However, although it works I still dont
understand why it works (I'm the kind of geek that has to know why).
So can anyone help me understand the code:

Dim sFiles() As String = Directory.GetFiles("C:\Windows", "*.exe",
SearchOption.AllDirectories)

I know the first part is the variable declaration but what about the
second part... Directory.GetFiles and SearchOption.AllDirectories

Also the MsgBox statement from the previous post... what does the {0}
mean? and what does UBound(sFiles) mean?

Any help/advice would be greatly appreciated. I just want a firm
understanding of it while I try to learn how to program. Thanks.- Hide quoted text -

- Show quoted text -

OK... So in the code:

MsgBox(String.Format("Number of EXE files found = {0}, UBound(sFiles)
+ 1))

Why does {0} return the number of files... seems like it would return
the name of the first file it found because UBound is useed after
calling {0}.

.



Relevant Pages

  • Re: vb.net search network drive
    ... ListAllFiles sub if that helps. ... Dim sFilesAs String ... array of strings - so what we are doing is matching up the sFiles ... UBound comes into play. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: vb.net search network drive
    ... Dim sFiles() As String ... array of strings - so what we are doing is matching up the sFiles ... UBound comes into play. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: vb.net search network drive
    ... Dim sFiles() As String ... array of strings - so what we are doing is matching up the sFiles ... UBound comes into play. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: vb.net search network drive
    ... Dim sFiles() As String ... array of strings - so what we are doing is matching up the sFiles ... UBound comes into play. ...
    (microsoft.public.dotnet.languages.vb)
  • Help in French|Spanish|German translation.
    ... I am also an author of User-defined string functions. ... WORDTRANEX (cSearched, cArExpressionSought | cExpressionSough, ... each string of the array is searched ... If the parameter nArStartOccurrence is -1 or omitted, the replacement starts ...
    (microsoft.public.fox.helpwanted)

Loading