Re: vb.net search network drive
- From: "Computer geek" <JohnTAllen@xxxxxxxxx>
- Date: 13 Mar 2007 13:45:26 -0700
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}.
.
- Follow-Ups:
- Re: vb.net search network drive
- From: rowe_newsgroups
- Re: vb.net search network drive
- References:
- vb.net search network drive
- From: Computer geek
- Re: vb.net search network drive
- From: ShaneO
- Re: vb.net search network drive
- From: ShaneO
- Re: vb.net search network drive
- From: Computer geek
- Re: vb.net search network drive
- From: rowe_newsgroups
- vb.net search network drive
- Prev by Date: Re: Problem using BackGroundWorker to ping multiple LAN hosts
- Next by Date: Re: vb.net search network drive
- Previous by thread: Re: vb.net search network drive
- Next by thread: Re: vb.net search network drive
- Index(es):
Relevant Pages
|
Loading