Get UNC for local file

mmitchell

Registered User.
Local time
Today, 17:07
Joined
Jan 7, 2003
Messages
80
I need to get the UNC for a file that is local the the PC the code is running on.

For example: c:\This is the dir\this is the sub\12345.txt

I need this in UNC format.

I am using the Common Dialog, but if there is a better way then I am open. I can use this for the actual network PC but not local.

Thanks.
 
I got this code somewhere either in the help or at the knowledge base. Try it and adapt it to get what you want:

Public Function FolderInformation()

Dim fso As Object
Dim Drive_Message As String
Dim dc As Object
Dim n As String
Dim d As Object
Dim strDriveType As String

On Error GoTo diskerror

Set fso = CreateObject("Scripting.FileSystemObject")
Set dc = fso.Drives

For Each d In dc
Drive_Message = Drive_Message & d.DriveLetter & " - "
If d.drivetype = 3 Then
n = d.ShareName
Else
n = d.VolumeName
End If
Select Case d.drivetype
Case 0
strDriveType = " (Unknown)"
Case 1
strDriveType = " (Removable)"
Case 2
strDriveType = " (Fixed)"
Case 3
strDriveType = " (Network)"
Case 4
strDriveType = " (CDRom)"
Case 4
strDriveType = " (RamDisk)"
Case Else
strDriveType = " (UnknownOther)"
End Select
Debug.Print d.drivetype
Drive_Message = Drive_Message & n & " - " & d.drivetype & strDriveType & vbCrLf
Next

MsgBox Drive_Message, vbOKOnly, "Drive List"

diskerror:

If Err.Number = 71 Then 'Trap the "Drive Not Ready" Error.
MsgBox "no disk in removable drive"
Resume Next
End If

End Function
 
Also, if it is always on C of the local computer, you can use this:

\\ComputerName\Folder\File

ComputerName is the name that your computer has been given, either by you or your admin. Open up the properties of My Computer to look for it.

In fact, I use that functionality to map a "drive" to a folder that I use extremely frequently. That way it's easier to access.
 

Users who are viewing this thread

Back
Top Bottom