PDA

View Full Version : ChDrive without mapping



tilamok
05-21-2011, 02:47 AM
Hi

Normally to switch to a new drive (x:), I can just write
chdrive "x:"

Howver I have access to a drive that is not mapped
So when I access the files, I have a link like
\\accounts\finance (file://\\accounts\finance) etc

I have tried to use chdrive \\accounts\finance (file://\\accounts\finance) but this does not work

Does anyone have the correct syntax when a drive is not mapped?
I don;t want to map it permanently because I get new drives all the time. So it might conflict with a new one

Thanks

Paul_Hossler
05-21-2011, 07:40 AM
http://www.ozgrid.com/forum/showthread.php?t=32173&page=1

Andy Pope's #6

As CHDIR() will not work with UNC directories try this example using an API. Change the servername and sharename to suit.


Private Declare Function SetCurrentDirectoryA Lib "kernel32" (ByVal lpPathName As String) As Long

Sub xx()
SetUNCPath "\\servername\sharedname"
End Sub

Sub SetUNCPath(Path As String)
Dim lngStatus As Long

lngStatus = SetCurrentDirectoryA(Path)
If lngStatus = 0 Then
MsgBox "Could not set path" & vbLf & Path, vbExclamation
End If

End Sub


I haven't tried it yet, but I have faith in Andy :thumb

I'll also put it into my collection of subs, since I need to get data off of UNC drives also

Paul

tilamok
05-21-2011, 08:27 AM
Thanks Paul