473,382 Members | 1,078 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

vb.net search network drive

Hello, I am new to VB.NET and programming in general. I have taught
myself a lot of the basics with vb.net but am still quite the novice.
I am working on a little application now and I need some help with one
part of the code. When a button is clicked I need to have it go out to
a network drive location and count how many files are present with a
certain file extension. Then store that number in a declared variable.
Is this possible? Can someone help? Also, would this be called a
method, function, or event procedure? Not exactly sure what the
difference is yet.

Mar 9 '07 #1
16 2816
On Mar 9, 11:12 am, "Computer geek" <JohnTAl...@gmail.comwrote:
Hello, I am new to VB.NET and programming in general. I have taught
myself a lot of the basics with vb.net but am still quite the novice.
I am working on a little application now and I need some help with one
part of the code. When a button is clicked I need to have it go out to
a network drive location and count how many files are present with a
certain file extension. Then store that number in a declared variable.
Is this possible? Can someone help? Also, would this be called a
method, function, or event procedure? Not exactly sure what the
difference is yet.
Here's a quick module that I wrote a long time ago for another poster.
Beware I air-modified it just now to let you specify the extension
type so it might have some bugs. You should be able to modify the
procedure to count the files and return that value.

Let me know how it works out (or if you need any help modifying it)

Thanks,

Seth Rowe
Module Module1

Sub Main()
ListAllFiles("C:/", "exe")
Console.WriteLine("done")
Console.Read()
End Sub

' Pass just the extension --i.e. just exe not .exe or *.exe
Private Sub ListAllFiles(ByVal path As String, ByVal extension As
String)
Try
Dim filenames() As String =
System.IO.Directory.GetFiles(path, String.Format("*.{0}", extension)
For i As Int16 = 0 To filenames.Length - 1
' Possibly increment your counter here
Console.WriteLine(filenames(i))
Next
Dim directories() As String =
System.IO.Directory.GetDirectories(path)
For i As Int16 = 0 To directories.Length - 1
ListAllFiles(directories(i), extension)
Next
Catch ex As Exception
' do nothing
End Try
End Sub

End Module

Mar 9 '07 #2
Computer geek wrote:
Hello, I am new to VB.NET and programming in general. I have taught
myself a lot of the basics with vb.net but am still quite the novice.
I am working on a little application now and I need some help with one
part of the code. When a button is clicked I need to have it go out to
a network drive location and count how many files are present with a
certain file extension. Then store that number in a declared variable.
Is this possible? Can someone help? Also, would this be called a
method, function, or event procedure? Not exactly sure what the
difference is yet.
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))
ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
Mar 9 '07 #3
ShaneO wrote:
Computer geek wrote:
>Hello, I am new to VB.NET and programming in general. I have taught
myself a lot of the basics with vb.net but am still quite the novice.
I am working on a little application now and I need some help with one
part of the code. When a button is clicked I need to have it go out to
a network drive location and count how many files are present with a
certain file extension. Then store that number in a declared variable.
Is this possible? Can someone help? Also, would this be called a
method, function, or event procedure? Not exactly sure what the
difference is yet.

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))
ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
MISTAKE: Sorry, the second line is supposed to be "+ 1", not "- 1".

ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
Mar 9 '07 #4
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.
Mar 10 '07 #5
On Mar 9, 8:55 pm, ShaneO <spc...@optusnet.com.auwrote:
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.

Mar 13 '07 #6
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...@gmail.comwrote:
On Mar 9, 8:55 pm, ShaneO <spc...@optusnet.com.auwrote:
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.
Mar 13 '07 #7
On Mar 13, 4:18 pm, "rowe_newsgroups" <rowe_em...@yahoo.comwrote:
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...@gmail.comwrote:
On Mar 9, 8:55 pm, ShaneO <spc...@optusnet.com.auwrote:
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}.

Mar 13 '07 #8
On Mar 13, 4:45 pm, "Computer geek" <JohnTAl...@gmail.comwrote:
On Mar 13, 4:18 pm, "rowe_newsgroups" <rowe_em...@yahoo.comwrote:
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...@gmail.comwrote:
On Mar 9, 8:55 pm, ShaneO <spc...@optusnet.com.auwrote:
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}.

{0} is replaced by the value of (UBound(sFiles) + 1) as UBound returns
the number of the last string not the string itself. To get the string
you would need to do sFiles(UBound(sFiles)).

Thanks,

Seth Rowe

Mar 13 '07 #9
rowe_newsgroups wrote:
On Mar 13, 4:45 pm, "Computer geek" <JohnTAl...@gmail.comwrote:
>On Mar 13, 4:18 pm, "rowe_newsgroups" <rowe_em...@yahoo.comwrote:
>>>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.
Mar 14 '07 #10
On Mar 14, 1:07 am, ShaneO <spc...@optusnet.com.auwrote:
rowe_newsgroups wrote:
On Mar 13, 4:45 pm, "Computer geek" <JohnTAl...@gmail.comwrote:
On Mar 13, 4:18 pm, "rowe_newsgroups" <rowe_em...@yahoo.comwrote:
>>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?

Mar 14 '07 #11
On Mar 14, 8:36 am, "Computer geek" <JohnTAl...@gmail.comwrote:
On Mar 14, 1:07 am, ShaneO <spc...@optusnet.com.auwrote:
rowe_newsgroups wrote:
On Mar 13, 4:45 pm, "Computer geek" <JohnTAl...@gmail.comwrote:
>On Mar 13, 4:18 pm, "rowe_newsgroups" <rowe_em...@yahoo.comwrote:
>>>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

Mar 14 '07 #12
On Mar 14, 8:47 am, "rowe_newsgroups" <rowe_em...@yahoo.comwrote:
On Mar 14, 8:36 am, "Computer geek" <JohnTAl...@gmail.comwrote:


On Mar 14, 1:07 am, ShaneO <spc...@optusnet.com.auwrote:
rowe_newsgroups wrote:
On Mar 13, 4:45 pm, "Computer geek" <JohnTAl...@gmail.comwrote:
On Mar 13, 4:18 pm, "rowe_newsgroups" <rowe_em...@yahoo.comwrote:
>>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- 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.

Mar 14 '07 #13
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...
If sFiles.Length = 0 Then
Msgbox("No files found")
Else
Msgbox(String.Format("{0} Files found", sFiles.Length)
Endif
I'll want it to pause briefly before moving to the next step. Just so
the display doesn't fill up real fast.
While you could use Thread.Sleep or a timer to do this, I wouldn't
recommend it. Instead why not have have different buttons to do the
different tasks? Like have one for finding unsent faxes, another for
checking network connectivity, etc. That way you don't have to sit
through all the tasks just to get to the one you want to see. And if
you want a "do all" button that button can call the PerformClick()
method on the others, however you would need to implement some sort of
timer here. If you need help wiring up a timer let us know - we'll be
happy to help.

Thanks,

Seth Rowe

On Mar 14, 11:18 am, "Computer geek" <JohnTAl...@gmail.comwrote:
On Mar 14, 8:47 am, "rowe_newsgroups" <rowe_em...@yahoo.comwrote:
On Mar 14, 8:36 am, "Computer geek" <JohnTAl...@gmail.comwrote:
On Mar 14, 1:07 am, ShaneO <spc...@optusnet.com.auwrote:
rowe_newsgroups wrote:
On Mar 13, 4:45 pm, "Computer geek" <JohnTAl...@gmail.comwrote:
>On Mar 13, 4:18 pm, "rowe_newsgroups" <rowe_em...@yahoo.comwrote:
>>>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- 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.

Mar 14 '07 #14
On Mar 14, 2:44 pm, "rowe_newsgroups" <rowe_em...@yahoo.comwrote:
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...

If sFiles.Length = 0 Then
Msgbox("No files found")
Else
Msgbox(String.Format("{0} Files found", sFiles.Length)
Endif
I'll want it to pause briefly before moving to the next step. Just so
the display doesn't fill up real fast.

While you could use Thread.Sleep or a timer to do this, I wouldn't
recommend it. Instead why not have have different buttons to do the
different tasks? Like have one for finding unsent faxes, another for
checking network connectivity, etc. That way you don't have to sit
through all the tasks just to get to the one you want to see. And if
you want a "do all" button that button can call the PerformClick()
method on the others, however you would need to implement some sort of
timer here. If you need help wiring up a timer let us know - we'll be
happy to help.

Thanks,

Seth Rowe

On Mar 14, 11:18 am, "Computer geek" <JohnTAl...@gmail.comwrote:
On Mar 14, 8:47 am, "rowe_newsgroups" <rowe_em...@yahoo.comwrote:
On Mar 14, 8:36 am, "Computer geek" <JohnTAl...@gmail.comwrote:
On Mar 14, 1:07 am, ShaneO <spc...@optusnet.com.auwrote:
rowe_newsgroups wrote:
On Mar 13, 4:45 pm, "Computer geek" <JohnTAl...@gmail.comwrote:
On Mar 13, 4:18 pm, "rowe_newsgroups" <rowe_em...@yahoo.comwrote:
>>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- 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.- Hide quoted text -

- Show quoted text -
WOW... a timer. Would that be a little out of the bounds of a beginner
programmer like myself? I actually did want it to perform all the
functions with one click because the idea of it is for when I am on
vacation or out of the office, my boss can just click the button and
see what the status is on everything. That way if something is out of
sort she can call me and I can take care of it. I hate coming into
work after days off and things are all screwed up. Know what I
mean :-) So this is giving me a good reason to start to learn how to
program. But before I go any further with that.... what about error
checking (my book is very vague about it). Seems like I remember
seeing some code somewhere like "On Err ...... Go to next" or
something like that. Is that something I should learn and put into
place? Like maybe it can't find the K:\ drive I specified. Let me know
what you think.

Mar 14 '07 #15
Computer geek wrote:
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.
Why not just place a Label above your ListBox, that way the Label won't
scroll-off the page if there's a lot of files being listed -

Dim sFiles() As String = System.IO.Directory.GetFiles("K:\AutoFax\",
"*.fax")
If sFiles.Length 0 Then
Label1.Text = String.Format("There are {0} fax files waiting to be
sent", sFiles.Length)
Else
Label1.Text = "All faxes have been successfully sent."
End If

Note the following points:

1. I've removed your String.Format function from the first line. It was
illogical to use it with a known value like "fax". If you know the
value, then just use it in the string.
2. I've included the "If" that you mentioned you wanted.
3. Generally, watch out for the way you're using "String.Format". Take
another look at your second line.
4. This may be a little ahead of you at this time, but, if you decide to
use the Label option I've suggested and you're going to check for
additional files, do your next check and just add to the already
displayed Label Text. eg. - Label1.Text = Label1.Text & vbCrLf &
String.Format("There are also {0} whatever files waiting to be sent",
sWhatever.Length)

I hope this helps you.

ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
Mar 14 '07 #16
On Mar 14, 5:17 pm, ShaneO <spc...@optusnet.com.auwrote:
Computer geek wrote:
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.

Why not just place a Label above your ListBox, that way the Label won't
scroll-off the page if there's a lot of files being listed -

Dim sFiles() As String = System.IO.Directory.GetFiles("K:\AutoFax\",
"*.fax")
If sFiles.Length 0 Then
Label1.Text = String.Format("There are {0} fax files waiting to be
sent", sFiles.Length)
Else
Label1.Text = "All faxes have been successfully sent."
End If

Note the following points:

1. I've removed your String.Format function from the first line. It was
illogical to use it with a known value like "fax". If you know the
value, then just use it in the string.
2. I've included the "If" that you mentioned you wanted.
3. Generally, watch out for the way you're using "String.Format". Take
another look at your second line.
4. This may be a little ahead of you at this time, but, if you decide to
use the Label option I've suggested and you're going to check for
additional files, do your next check and just add to the already
displayed Label Text. eg. - Label1.Text = Label1.Text & vbCrLf &
String.Format("There are also {0} whatever files waiting to be sent",
sWhatever.Length)

I hope this helps you.

ShaneO

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

- Show quoted text -
Do either of you know of any good online resources that clearly define
different functions/methods in vb.net? I've found a couple sites but
they are not very intuitive for a beginner like myself.

Mar 28 '07 #17

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Robert Tarantino | last post by:
Hello, I am trying to find a way to create a scheduled task or service that will copy my local profile folders under "Documents and settings" to a network drive. This would allow me to restore...
2
by: giloosh99 | last post by:
Hello, Im grabbing tables via VB code using visual foxpro ODBC drives. The tables directory is in a mapped network drive. The code works fine and does the job, however if the computer is idle for...
5
by: Niloday | last post by:
Hi All, I am trying to access a mapped network drive from a service that I have created. The service needs to create/delete folders/files on a network drive. When I tried to connect to a...
1
by: brian.oneil2 | last post by:
Is there a way to install this onto a network file share and allow a team to access it? I would say share a CD from a networked CD drive, but there are multiple CD's that would have to be inserted....
8
by: Lam | last post by:
HI anyone knows how can I open a mapped network file in C#? I try string file = @"T:\file.txt"; it shows me the error: "Could not find a part of the path" but if I copy the file to my C dirve,...
5
by: Nirosh | last post by:
Hi All, Can any one suggest me a best way to do this .. I have a thrid party tool "EXE" that we need to use with our web service to manipulate some complex XML files, which reside in a...
3
by: Henners | last post by:
Hi There We are migrating our network file system from Novell to Windows. (There are pros and cons).... In this process, we have noticed that a good bunch of user created access databases...
3
by: Chung Leong | last post by:
Here's the rest of the tutorial I started earlier: Aside from text within a document, Indexing Service let you search on meta information stored in the files. For example, MusicArtist and...
3
by: Barry Flynn | last post by:
Hi I am working with a VB 2005 program which has been converted from VB6. It writes data out to a flat file, with code like the following line WriteLine(riFileNo, "Hist", lsAssetID,...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.