How to check if a path exists 
Author Message
 How to check if a path exists

Can somebody tell me how to program a Visual Basic application that checks
if a drive, that is located on a network, exists.
I really need help! I want to create such a programe because I have a
chatprogram installed on a fileserver.
The chatserver of that program is running on that machine. Al the clients
who are connected to the network must check if the fileserver is connected
to the network. If it is connected, the client's should run a file to
activate the chatclient


Wed, 18 Jun 1902 08:00:00 GMT  
 How to check if a path exists


Quote:
>Can somebody tell me how to program a visual basic application that checks
>if a drive, that is located on a network, exists.

If Dir( MyPath$, vbDirectory Or vb Hidden or vbSystem )  = "" Then
   MsgBox MyPath$ + " Not found"
End If

or look at the FindFirst API



Wed, 18 Jun 1902 08:00:00 GMT  
 How to check if a path exists

Quote:



> >Can somebody tell me how to program a visual basic application that checks
> >if a drive, that is located on a network, exists.

> If Dir( MyPath$, vbDirectory Or vb Hidden or vbSystem )  = "" Then
>    MsgBox MyPath$ + " Not found"
> End If

> or look at the FindFirst API

I believe at one time using an invalid drive letter in Dir()
generated an error ("Device not found" or somesuch).  Also,
under some networks, the only way I found to determine if
a path was available was to actually create a temporary
file there.  Here's the code I use:

SUB CheckPath (txt$, retcd)

'
' This routine supplies a trailing \ to a non-null path not ending : or \
'
  IF LEN(txt$) > 0 THEN
    IF INSTR(":\", RIGHT$(txt$, 1)) = 0 THEN
      txt$ = txt$ + "\"
    END IF
  END IF

  retcd = TRUE

  CheckPathFile$ = txt$ + "CHKPATH.TMP"
  IF LEN(XDir$(CheckPathFile$)) = 0 THEN
    ' we try to create it
  ELSE
    ' a file exists by this name, so we were able to access the path ...
    EXIT SUB
  END IF

  CHKNUM = FREEFILE
  ON ERROR GOTO CheckPathErr1
CheckPathTry1:
  openerr = FALSE
  OPEN CheckPathFile$ FOR OUTPUT AS #CHKNUM
CheckPathRes1:
  IF openerr THEN
    retcd = FALSE
    GOTO CheckPathWrapup
  END IF

  ON ERROR GOTO CheckPathErr3
CheckPathTry3:
  closeerr = FALSE
  CLOSE CHKNUM
  KILL CheckPathFile$
CheckPathRes3:
  IF closeerr THEN
    ' nothing really to do here ...
  END IF

CheckPathWrapup:
  ON ERROR GOTO 0
  EXIT SUB

CheckPathErr1:
  ecode = ERR
  openerr = TRUE
  RESUME CheckPathRes1

CheckPathErr3:
  ecode = ERR
  closeerr = TRUE
  RESUME CheckPathRes3

END SUB

FUNCTION XDir$ (p$)

  XDirErrFlag = FALSE
  ON ERROR GOTO XDirError
  IF LEN(p$) = 0 THEN                      ' NOTE!  DIR$("") is the same
    txt$ = DIR$                            '        as DIR$("*.*") and is
  ELSE                                     '        NOT the same as
    txt$ = DIR$(p$)                        '        DIR$ with no argument!
  END IF
XDirResume:
  ON ERROR GOTO 0
  IF XDirErrFlag THEN
    txt$ = ""
  END IF
  XDir$ = txt$
  EXIT FUNCTION

XDirError:
  XDirErrFlag = TRUE
  RESUME XDirResume

END FUNCTION



Wed, 18 Jun 1902 08:00:00 GMT  
 How to check if a path exists



[snips]

Quote:
> I believe at one time using an invalid drive letter in Dir()
> generated an error ("Device not found" or somesuch).  Also,
> under some networks, the only way I found to determine if
> a path was available was to actually create a temporary
> file there.

Far from fewlproof - what if I only have read permissions in the folder?

Cheers.



Wed, 18 Jun 1902 08:00:00 GMT  
 How to check if a path exists

Quote:




> [snips]

> > I believe at one time using an invalid drive letter in Dir()
> > generated an error ("Device not found" or somesuch).  Also,
> > under some networks, the only way I found to determine if
> > a path was available was to actually create a temporary
> > file there.

> Far from fewlproof - what if I only have read permissions in the folder?

> Cheers.

Then you should be able to trap the "Permission denied" error,
which should imply that the path exists.  As I said, it was
a particular type of network (can't remember which, now), that
forced me to use the "create-file" trick to determine if the
path existed; other methods were not foolproof either.

Joe



Wed, 18 Jun 1902 08:00:00 GMT  
 How to check if a path exists

Quote:
>Far from fewlproof - what if I only have read permissions in the folder?

Not far enough ;-): If you're r/o you don't need to know the path's
existence - try to open and read and you'll see.


Wed, 18 Jun 1902 08:00:00 GMT  
 How to check if a path exists
On Sun, 28 May 2000 15:35:08 -0400, "Joseph M. Erhardt"

Quote:

>I believe at one time using an invalid drive letter in Dir()
>generated an error ("Device not found" or somesuch).  Also,
>under some networks, the only way I found to determine if
>a path was available was to actually create a temporary
>file there.  Here's the code I use:

1) You should check whether the drive exists anyway

2) This will work as well as : Dir( MyPath, attributes )

    If (GetAttr(MyPath) And vbDirectory) = vbDirectory Then

Obviously all should be 'boxed up' with error handling.



Wed, 18 Jun 1902 08:00:00 GMT  
 How to check if a path exists
Visual Basic 5.0 or 6.0
===========================================
In the Project References select the Microsoft Scripting Runtime

then do:

Sub main()
    Dim myDrives As New FileSystemObject

    If
myDrives.FileExists("\\Alicia_1\Alicia_1_C\WinNT\System32\scrrun.dll") Then
        Debug.Print "I found the file!"
        Debug.Print "================="
        Debug.Print Dir("\\Alicia_1\Alicia_1_C\WinNT\System32\scrrun.dll")
    End If

End Sub

or better

Public Sub Main()
    If ServerExists("\\MachineName\DriveShareName") Then
        ' Do what you need to do
    End If
End Sub

Public Function ServerExists( URL_2_root As String) As Boolean
    Dim myDrives As New FileSystemObject

    If myDrives.FileExists(URL_2_root) Then
        Debug.Print "I found the file!"
        ServerExists = True
    Else
        ServerExists = False
    End If

End Sub


Quote:
> Can somebody tell me how to program a visual basic application that checks
> if a drive, that is located on a network, exists.
> I really need help! I want to create such a programe because I have a
> chatprogram installed on a fileserver.
> The chatserver of that program is running on that machine. Al the clients
> who are connected to the network must check if the fileserver is connected
> to the network. If it is connected, the client's should run a file to
> activate the chatclient



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Checking if folder/path exists: Outlook Form

2. Check if path exists

3. Check if UNC path exists

4. fRefreshLinks Doesn't work if path doesn't exist

5. Existing Database Path

6. File exists in Dos Path?

7. Finding if File and Path Exists?

8. Reading Target path from *existing* shortcut files.

9. Path exists or not?

10. Path exists or not?

11. How do you tell if PATH exists

12. Detecting if a path exists...

 

 
Powered by phpBB® Forum Software