Board index » Visual Studio » validating network path

validating network path

Visual Studio151
I know how to validate a standard local path (ie. c:\windows), but I am not

having luck validating a path such as (\\server\dir\dir). Could someone

point me int he right direction?

Thanks!!

--

--------

Jon


-
 

Re:validating network path

Figured it out...



Dim fso As New FileSystemObject, b as Boolean



b = fso.FolderExists("\\server\path\dir")







"Jon" <ruffles_@msn.com>wrote in message

Quote
I know how to validate a standard local path (ie. c:\windows), but I am

not

having luck validating a path such as (\\server\dir\dir). Could someone

point me int he right direction?

Thanks!!

--

--------

Jon









-

Re:validating network path

The FileSystemObject is meant for scripting. It requires an additional

reference in the application. If distributed you will find that there are

many versions out there. It is also slower that most API or native VB

approaches. Most of the regulars here will advise against using the

FileSystemObject.



My way may not be the best... I'm sure you will get other replies and

suggestions.



Al Reid



"Jon" <ruffles_@msn.com>wrote in message

Quote
Thanks for that api method. Do you think it is more reliable than the

FileSystemObject method I used above?





"Al Reid" <areidjr@reid-home.com>wrote in message

news:eMQZXwFfDHA.2332@TK2MSFTNGP12.phx.gbl...

>Here is what I use. It works on both local and network (UNC) path

names.

>

>Public Declare Function PathIsDirectory Lib "shlwapi.dll" Alias

>"PathIsDirectoryA" (ByVal pszPath As String) As Boolean

>

>Public Function IsPathValid(ByVal Path As String) As Boolean

>

>On Error GoTo ERROR_HANDLER

>

>IsPathValid = PathIsDirectory(Path)

>

>EXIT_HANDLER:

>' Place Procedure Clean-up Code Here

>Exit Function

>ERROR_HANDLER:

>' Place Error Handler Here

>Resume EXIT_HANDLER

>Resume

>End Function

>

>

>Al Reid

>

>"Jon" <ruffles_@msn.com>wrote in message

>news:ui0B5pFfDHA.4024@TK2MSFTNGP11.phx.gbl...

>>I know how to validate a standard local path (ie. c:\windows), but I

am

>not

>>having luck validating a path such as (\\server\dir\dir). Could

someone

>>point me int he right direction?

>>Thanks!!

>>--

>>--------

>>Jon

>>

>>

>

>









-

Re:validating network path

Hi Jon --



Quote
I know how to validate a standard local path (ie. c:\windows), but I

am not having luck validating a path such as (\\server\dir\dir).

Could someone point me int he right direction?



What's wrong with how you're doing it for a local path? Same thing, assuming you

were doing that right. <G>



Public Function IsDirectory(ByVal SpecIn As String) As Boolean

Dim Attr As Long



' Special cases: "C:", "..", "." all generate

' "Path not found" errors when passed to GetAttr.

' "D:\" may return an attribute value of 0 if

' it refers to a removeable drive.

Select Case Len(SpecIn)

Case 1

If SpecIn = "." Then

IsDirectory = True

Exit Function

End If

Case 2

If SpecIn = ".." Or InStr(SpecIn, ":") = 2 Then

IsDirectory = True

Exit Function

End If

Case 3

If InStr(SpecIn, ":\") = 2 Then

IsDirectory = True

Exit Function

End If

End Select



' Guard against bad SpecIn by ignoring errors.

' Get attribute of SpecIn.

On Error Resume Next

Attr = GetAttr(SpecIn)

On Error GoTo 0



' Check for presence of Directory attribute.

If (Attr And vbDirectory) = vbDirectory Then

IsDirectory = True

End If

End Function



Later... Karl

--

[Microsoft Basic: 1976-2001, RIP]





-