Re: vb.net search network drive
- From: "Computer geek" <JohnTAllen@xxxxxxxxx>
- Date: 14 Mar 2007 08:18:04 -0700
On Mar 14, 8:47 am, "rowe_newsgroups" <rowe_em...@xxxxxxxxx> wrote:
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:I'll try :-)
Dim sFiles() As String = Directory.GetFiles("C:\Windows", "*.exe",
SearchOption.AllDirectories)
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- Hide quoted text -
- Show quoted text -
The purpose of this program is to check various system functions at
the beginning of the day. The first one I'm doing is to check for fax
files that did not get sent over night. This is what I have so far:
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnStart.Click
'Checks network drive for files of .fax type
Dim sFiles() As String = System.IO.Directory.GetFiles("K:
\AutoFax\", String.Format("*.{0}", "fax"))
'Displays the number of fax files in the listbox
lstResults.Items.Add(String.Format("There are " &
UBound(sFiles) + 1 & " fax files waiting to be sent"))
End Sub
Ideally, I'd like to use an IF statment to test if the are more than 0
files to display what I have above. And if not, display a differnt
message. But I was not able to get an IF statement to work. I think it
has something to do with how you test a String value... The reason I
asked about pausing was because after it does the check for faxes,
I'll want it to pause briefly before moving to the next step. Just so
the display doesn't fill up real fast.
.
- Follow-Ups:
- Re: vb.net search network drive
- From: ShaneO
- 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
- Re: vb.net search network drive
- From: Computer geek
- Re: vb.net search network drive
- From: rowe_newsgroups
- 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: System.Net.Mail.MailMessage
- Next by Date: Re: VB 2005 and Exchange Server
- Previous by thread: Re: vb.net search network drive
- Next by thread: Re: vb.net search network drive
- Index(es):
Relevant Pages
|