Re: vb.net search network drive

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



On Mar 14, 8:36 am, "Computer geek" <JohnTAl...@xxxxxxxxx> wrote:
On Mar 14, 1:07 am, ShaneO <spc...@xxxxxxxxxxxxxxx> wrote:



rowe_newsgroups wrote:
On Mar 13, 4:45 pm, "Computer geek" <JohnTAl...@xxxxxxxxx> wrote:
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.

Well done Seth, I couldn't have explained it any better myself.

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)

Yes, if I'd used "sFiles.Length" instead of "UBound(sFiles)" I would not
have made my original mistake of hitting the minus sign instead of the
plus sign. I guess old habits are sometimes hard to break and I need to
dispense with using UBound.

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!

So now you can see what the {0} does, my second line should really have
been -

MsgBox(String.Format("Number of EXE Files Found = {0}", sFiles.Length))

ShaneO

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

- Show quoted text -

Thanks for the help guys. How about when I add things to a listbox. Is
there a way pause shortly between different lines you send to a
listbox?

Could you post your code?

Two ways are to use either System.Threading.Thread.Sleep(# of
milliseconds) or to set up the routine on a timer.

Thanks,

Seth Rowe

.



Relevant Pages

  • 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
    ... 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
    ... This statement accomplishes the same thing as my recursively called ... 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)