Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

UNC Path exists

Status
Not open for further replies.

shootsie

Programmer
Apr 12, 2001
43
US
Does anyone know how to determine whether a UNC path exists in VB? I have tried everything and it doesn't work consistantly, even though it may work in debut mode. I have tried:

fso.folderexists("//path/test")
dir("//path/test")

and it does not work consistently.

Thanks,
Ashley
 
Also, my permissions are correct to verify.

Thanks.
 

Hmmm...

this...
[tt]
fso.folderexists("//path/test")
dir("//path/test")
[/tt]

needs to be changed to...
[tt]
fso.folderexists("\\path\test")
dir("\\path\test")
[/tt]

Good Luck

 
I'm sorry, in the frustration to find the solution I typed it in wrong. I'm actually copying the path directly from explorer.
 

Ok, well then you should use something like ...
[tt]
Public Function DoesPathExist(PathToTest As String) As Boolean

If Right(PathToTest, 1) <> &quot;\&quot; Then PathToTest = PathToTest & &quot;\&quot;

If Dir(PathToTest, vbDirectory) <> &quot;&quot; Then DoesPathExist = True

End Function
[/tt]

Good Luck


 
Sorry, but I tried that too to no avail. I wish I could list everything I tried... it seems as if the app will not wait for the OS to try to connect to the network path. I ended up putting a try-catch block... it seems to work OK although it doesn't really accomplish what I wanted exactly.
 
I tried the above and got the error &quot;bad file name or number&quot; if the path didn't exist. Don't seem to need trailing slash either, work same with or without.

I'll look for something else but if nothing found I guess you could trap the error and use above...
 
>needs to be changed to...

>fso.folderexists(&quot;\\path\test&quot;)

Not true; fso attempts to normalise paths, and can hanle all sorts of (horrendous) variants
 

>Not true; fso attempts to normalise paths, and can hanle all sorts of (horrendous) variants

Byte why confuse it??? :)

 
I meant the one from vb5prgrmr (dir())
Yeah must be some other problem fso.fileexists seems to work fine for me too.

If you don't need the Scripting runtime for anything else you can also use the API function PathFileExists

Public Declare Function PathFileExists Lib &quot;shlwapi&quot; _
Alias &quot;PathFileExistsA&quot; _
(ByVal pszPath As String) As Long


tmp = PathFileExists(&quot;\\server\share&quot;)


Retrurns 1 if exists, 0 if not.


 
Is the network cable plugged into the back of the computer:)

&quot;Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.&quot;
 
Unfortunately, yes. I have had a *little* headway that might give someone some insight:

I have included a third party control that is a file explorer combo box. It allows me to actually go through explorer, select the folder I want to export to over the network, and then select it. Now when I do:

If (fso.FolderExists(FWComboFileFolder1.Value)) Then
call msgbox &quot;WORKS!&quot;
end if

I get a msgbox. FWComboFileFolder1.Value is equal to the same path (ie, &quot;\\path\test&quot;) over the network as previously when the user entered it in. EXACTLY. I am sure of this. When the user sets this string value it does not work.

I still need the confirmation of directory to work, however, since later on this app will run without user input. Anything??
 
Gotta be somg funny about what you are doing when the user enters it cause both fso.folderexists and the API call to PathFileExista definitely work...

Test it with however it will get the path with no user input??
 
In other words, if I have a constant string or if I pull in the path name from an INI file.

Also, keep in mind that this problem NEVER happens in debug mode. Only when I COMPILE the app.

Ok... I just realized I left an important part out that may or may not have something to do with it. I'm running it as a service. *shrug*

 
Ahhh, could be a rights issue? I don't have time to test righ now but if you log on as the same account as the service is running under is should behave the same way in debug mode as when compiled and running as a service.
 
At this point I'm inclined to think it's either that or a network issue. I'll let everyone knwo if I come up with an absolute solution to this. Thanks so much for your help...


...still pluggin' away... -shootsie
 
Just specify that the service run under a domain account rather that the Local System.

I've written services in VB that access Exchange mailboxes and that is certainly a network resource. Just gave permissions to the mailbox to the same account I had the service running under, could do the same with a share.

I love when I see MS saying it doesn't recommend creating services with VB. I do it with the NTSvc.ocx control I downloaded from their site (and never had a problem).
 
I'm using that ocx as well. I'm understanding now what the problem is -- but still no finite solution. When I set the service to logon under a user account, it will no longer provide me with my form dialogue.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top