What is the most efficient way to do this using VB6:

I want to fill a ListBox with the files that are located in a folder
on a networked computer. Purely as an example, imagine the files were
located here:

\\MyOtherComputer\MyOtherComputersFolder

...Before my routine runs the procedure that will fill the ListBox
with the files from the above location, it would be great if I could
make sure that that path was currently valid first.

In other words, if "MyOtherComputer" is NOT currently a member of the
network, I want the routine to be stopped.

How would you VB6 experts go about detecting if a file path is
currently accessible?

Thanks in advance.

Re: Test to see if path is CURRENTLY VALID??? by Karl

Karl
Wed Jul 20 19:15:04 CDT 2005

Alan Mailer wrote:
> How would you VB6 experts go about detecting if a file path is
> currently accessible?

Here's the FAQ response:

Public Function IsDirectory(SpecIn As String) As Boolean
Dim Attr As Long

' Guard against bad SpecIn by ignoring errors.
On Error Resume Next

' Get attribute of SpecIn.
Attr = GetAttr(SpecIn)
If Err = 0 Then
' No error, so something was found.
' If Directory attribute set, then not a file.
If (Attr And vbDirectory) = vbDirectory Then
IsDirectory = True
Else
IsDirectory = False
End If
End If
End Function

Later... Karl
--
Working Without a .NET?
http://classicvb.org/petition



Re: Test to see if path is CURRENTLY VALID??? by Larry

Larry
Wed Jul 20 20:07:08 CDT 2005


"Karl E. Peterson" <karl@mvps.org> wrote
> Alan Mailer wrote:
> > How would you VB6 experts go about detecting if a file path is
> > currently accessible?
>
> Here's the FAQ response:
>
> Public Function IsDirectory(SpecIn As String) As Boolean
> Dim Attr As Long
>
> ' Guard against bad SpecIn by ignoring errors.
> On Error Resume Next
>
> ' Get attribute of SpecIn.
> Attr = GetAttr(SpecIn)
> If Err = 0 Then
> ' No error, so something was found.
> ' If Directory attribute set, then not a file.
> If (Attr And vbDirectory) = vbDirectory Then
> IsDirectory = True
> Else
> IsDirectory = False
> End If
> End If
> End Function


When I look at code like this, I have to wonder what would be lost
by using something a bit shorter:

Public Function IsDirectory(SpecIn As String) As Boolean
On Error Resume Next
IsDirectory = CBool(GetAttr(SpecIn) And vbDirectory)
End If


Maybe its just me, but I find the second edition slightly more 'readable'
than the first, with the added benefit taking up less space.

LFS

Re: Test to see if path is CURRENTLY VALID??? by Karl

Karl
Wed Jul 20 20:18:45 CDT 2005

Larry Serflaten wrote:
> When I look at code like this, I have to wonder what would be lost
> by using something a bit shorter:
>
> Public Function IsDirectory(SpecIn As String) As Boolean
> On Error Resume Next
> IsDirectory = CBool(GetAttr(SpecIn) And vbDirectory)
> End If
>
> Maybe its just me, but I find the second edition slightly more
> 'readable' than the first, with the added benefit taking up less
> space.

Yep, that's better. The other originated when linecount "mattered." <g>
--
Working Without a .NET?
http://classicvb.org/petition



Re: VB6: Test to see if path is CURRENTLY VALID??? by erewhon

erewhon
Thu Jul 21 02:22:23 CDT 2005

On Thu, 21 Jul 2005 00:01:42 GMT, Alan Mailer
<clarityassoc@earthlink.net> wrote:

>What is the most efficient way to do this using VB6:
>
>I want to fill a ListBox with the files that are located in a folder
>on a networked computer. Purely as an example, imagine the files were
>located here:
>
>\\MyOtherComputer\MyOtherComputersFolder
>
>...Before my routine runs the procedure that will fill the ListBox
>with the files from the above location, it would be great if I could
>make sure that that path was currently valid first.
>
>In other words, if "MyOtherComputer" is NOT currently a member of the
>network, I want the routine to be stopped.
>
>How would you VB6 experts go about detecting if a file path is
>currently accessible?

Check the attribute of the Directory

On Error Resume Next
Q = GetAttr( TheDir )
If Err = 0 Then
If ( Q And vbDirectory ) Then
DirExists = True