Obtain the share name of a folder on a server

wigi

Well-known Member
Joined
Jul 10, 2006
Messages
7,964
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
  3. Web
Hello all,

Does anyone know a way in VBA to get the share name(s) of a certain folder?

Detailed explanations:

I have access to a folder (say, D:\MyFolder) on a remote server in the network.
That folder is shared in order to have access, I do not have access anywhere else.
But I would like to programmatically obtain the share name, starting from in this example D:\MyFolder on the remote server.
Folder name is given and server name is given, and access to the folder is guaranteed.

Does anyone have an idea please?

Thanks in advance !
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Hi

Like this:

Code:
Function UNC_From_Mapped(MappedPath As String) As String
    Dim i As Long
    With CreateObject("WScript.Network").EnumNetworkDrives
        For i = 0 To .Count - 1 Step 2
            If LCase(.Item(i)) = LCase(MappedPath) Then UNC_From_Mapped = .Item(i + 1)
        Next
    End With
End Function

Actually, having re-read your question, I'm not entirely sure if this is what you want or even what you are looking for ;)
 
Last edited:
Upvote 0
Hi

Thanks for your suggestion, but I'm quite sure this is not what I'm after ;-)
 
Upvote 0
I'm not sure I follow what you want. Are you trying to find code to return the share name of a local folder (i.e. local to the machine running the code)? If the folder is on a remote machine would you not be accessing it via its share name anyway?
 
Upvote 0
Hello Rory

Let me explain this more clearly.
Me or any user of the application, should input 2 folder locations: 1 explicitly, and 1 implicitly.
The folder locations can be on the local machine or on a remote server.
The folder that is chosen explicitly, could be for example a share name: \\aexbeapps\ForecastModel\
It will (should) contain a configuration file: it is called tm1s.cfg. (I will test for the existence of the config file.)
One of the entries in this configuration file, is again a path like D:\TM1Data\ForecastModel\ (but this path could be local to the remote server machine)

The input of both folder names can be in any form: a path on the local machine or remote machine, share names can be used, and the like.
Hence, I need to check whether the 2 folders chosen "match".

For example, the config file contains D:\TM1Data\ForecastModel\
and the other folder chosen is a share name like \\aexbeapps\ForecastModel\
The share refers to the same folder, but I need to check this.
Alternatively: get the share name of the folder D:\TM1... and see if it matches.

Sorry for the confusion, it is not easy to explain.
I will check out CC's nice suggestions, I think this does what I need. I did not know GetDrive until now.
In any case, thanks CircledChicken and Rory.
 
Last edited:
Upvote 0
Why doesn't the code I supplied do that?

Hi Kyle

How would you call your function (what argument for MappedPath) in the example above?

Note, the location of the folder can be any folder, not just C: or D: on the remote machine.
 
Upvote 0
I'm not sure GetDrive will work since it will be looking at D:\whatever on the machine where the code is running.
 
Upvote 0
Regardless of having a solution or not at the moment, do you understand my question?

In essence: testing 2 folder locations, which could be on different machines, and share names could be used when defining the locations.

User rights will not be present or I assume they are sufficient.
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top