Tell me more ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I frequently want to share network paths to files with other folks on my team via email or chat. We have a lot of mapped drives here, both ones we set up ourselves and ones set up by our IT overlords. What I'd like to be able to do is to copy the full real path (not the drive letter) from Windows Explorer to send to folks.

Example: I have a file in my "Q:" drive, \\cartman\users\emueller, and I want to send a link to the file foo.doc therein to coworkers. When I copy the file path (shift+right click, "copy as path") it gets the file name "Q:\foo.doc". This is unhelpful to others, who would need to see \\cartman\users\emueller\foo.doc to be able to consume the link.

In Explorer it clearly knows it - in the address bar I see "Computer -> emueller (\\cartman\users) (Q:) ->". Is there a way to say "hey man copy that path as text with the \\cartman\users\emueller not the Q: in it?"

I know I could just set up mapped network locations instead of the mapped drives for the ones that I set up personally and avoid this problem, but most of the mapped drives like the "users" share come from our IT policy. I could just make a separate network location and then ignore my Q: drive but that's inconvenient (and they do it so they can move accounts across servers). Sure my emailed path might eventually break because I'm losing the drive letter indirection but that's OK with me.

share|improve this question
I'd sure like to see a solution for this problem. Any chance you can edit your post (which will hopefully trigger some more visibility for it)? – kmote Jul 26 '12 at 20:58

8 Answers

up vote 12 down vote accepted

I had exactly the same problem -- not everyone had the same mapped drives as me, or mapped to the same letters.

After much searching I found a context menu extension named Path Copy Copy on CodePlex (http://pathcopycopy.codeplex.com/) which is an extended version of a similar, older extension (called Pathcopy) has quite a few options for copying paths as text, including one for UNC paths -- example of the options available are shown below:

enter image description here

share|improve this answer

I just had the need for the same thing OP is asking and after searching on Google and reading the answers, none of them provided what I think the OP and I are looking for.

The problem here is that one may map a network share to Drive Y whereas someone else in the organization may have the same network share mapped as Drive X; therefore, sending a link such as Y:\mydirectory may not work for anyone else except me.

As the OP explains, Explorer does show the actual path in the Explorer bar, but you cannot copy it (typing is tedious and prone to errors, so this is not an option) even if you choose copy as path from the context menu:

enter image description here

So the solution I came up with (by copying someone else's code) was a little C# program that you can call from a context menu in Explorer and will allow you to translate the Mapped drive letter to the actual UNC path.

Here's the code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Utils
{
    //This is the only piece of code I wrote
    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            //Takes the parameter from the command line. Since this will
            //be called from the context menu, the context menu will pass it 
            //via %1 (see registry instructions below)
            if (args.Length == 1)
            {               
                Clipboard.SetText(Pathing.GetUNCPath(args[0]));
            }
            else
            {   
               //This is so you can assign a shortcut to the program and be able to
               //Call it pressing the shortcut you assign. The program will take
               //whatever string is in the Clipboard and convert it to the UNC path
               //For example, you can do "Copy as Path" and then press the shortcut you  
               //assigned to this program. You can then press ctrl-v and it will
               //contain the UNC path
                Clipboard.SetText(Pathing.GetUNCPath(Clipboard.GetText()));           
            }
        }
    }
}

And here's the Pathing class definition (I'll try to find the actual source as I can't remember where I found it):

public static class Pathing
{
    [DllImport("mpr.dll", CharSet = CharSet.Unicode, SetLastError = true)]
    public static extern int WNetGetConnection(
        [MarshalAs(UnmanagedType.LPTStr)] string localName,
        [MarshalAs(UnmanagedType.LPTStr)] StringBuilder remoteName,
        ref int length);
    /// <summary>
    /// Given a path, returns the UNC path or the original. (No exceptions
    /// are raised by this function directly). For example, "P:\2008-02-29"
    /// might return: "\\networkserver\Shares\Photos\2008-02-09"
    /// </summary>
    /// <param name="originalPath">The path to convert to a UNC Path</param>
    /// <returns>A UNC path. If a network drive letter is specified, the
    /// drive letter is converted to a UNC or network path. If the 
    /// originalPath cannot be converted, it is returned unchanged.</returns>
    public static string GetUNCPath(string originalPath)
    {
        StringBuilder sb = new StringBuilder(512);
        int size = sb.Capacity;

        // look for the {LETTER}: combination ...
        if (originalPath.Length > 2 && originalPath[1] == ':')
        {
            // don't use char.IsLetter here - as that can be misleading
            // the only valid drive letters are a-z && A-Z.
            char c = originalPath[0];
            if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
            {
                int error = WNetGetConnection(originalPath.Substring(0, 2),
                    sb, ref size);
                if (error == 0)
                {
                    DirectoryInfo dir = new DirectoryInfo(originalPath);

                    string path = Path.GetFullPath(originalPath)
                        .Substring(Path.GetPathRoot(originalPath).Length);
                    return Path.Combine(sb.ToString().TrimEnd(), path);
                }
            }
        }

        return originalPath;
    }
}

You build the program and put the executable somewhere in your PC, say for example, in c:\Utils

Now you add a context menu option in Explorer as so:

Regedit and then:

HKEY_CLASSES_ROOT\*\Directory\Shell

Right-click Shell --> New Key --> Name: "To UNC Path"
Right-click To UNC Path --> New Key --> Name: command
Right-click Default entry and select `Modify`
Value Data: c:\Utils\Utils.exe %1

You are done. Now you'll see this option when you right-click a directory from a mapped drive:

enter image description here

Note

I can provide the executable so you don't have to do the compilation yourself. Simply drop me a note here.

share|improve this answer

Maybe a long way around but open a cmd window. Then do net use > filename

Then open the filename and you can get the path:
Ex:

C:\Users\me\net use > drives.txt

Opening drives.txt

New connections will be remembered.
Status       Local     Remote                    Network
-------------------------------------------------------------------------------
             H:        \\server\c\proj\net       Microsoft Windows Network

Can copy \\server\c\prog\net from the file for your use.

Hope this helps.

share|improve this answer
simple and easy. All other solutions in the topic are very bulk... – radistao 2 days ago

Someone named Shawn Keene provided a solution to this in the Windows 7 Forum on the Microsoft website. It is in a feature called Network Place.

  1. Open Windows Explorer.

  2. Right-click on the Computer entry in the left pane and select “Add a network location”. Click next.

  3. Select the “Choose a custom network location” option (it was the only one presented to me) and click Next.

  4. Type in the UNC path desired and click Next twice. This adds an entry that shows up in left pane of Windows Explorer below the mapped drives, but it works just like a mapped drive and shows up that way in the Save dialog of applications.

  5. In Windows Explorer, navigate through that entry to the desired sub-directory and click in the blank area to the right of the bread crumbs path display in the top of the Windows Explorer screen and the UNC path appears and is highlighted.

share|improve this answer
if you're going to quote another source could you please link to that source as well? – DMA57361 Feb 17 '11 at 13:58
Originally from this post - the W7 source wasn't specifed there: countrykeepers.com/wp/?p=3017 – Mark Feb 17 '11 at 14:07
Hey, thanks for chiming in. I know about this, that's what I meant by "I could just set up mapped network locations instead of the mapped drives" in the question - it's that many of them come to me as mapped drives courtesy my IT department, and I'd like to be able to link those. But that's definitely a possible solution to some of the problem! – Ernest Mueller Feb 18 '11 at 14:24
P.S. I'd vote up your answer, but not enough rep, so "virtual +1!" – Ernest Mueller Feb 18 '11 at 14:28

Well, if I understand your question correctly, I think I've got a suitable workaround.*

Once you have copied the address from the Windows Explorer address bar, open your email message, hit ctrl-K (to insert a hyperlink) and paste the link into the Address field, then hit "OK" to close the dialog. The link will display the mapped drive letter as the root (Q:\foo.doc). However, if you r-click and select "Edit Hyperlink..." you will notice that the Address field displays the full UNC path (\\cartman\users\emueller\foo.doc). With your mouse in the Address field, hit ctrl-A and ctrl-C to copy the full path to your clipboard, then move your cursor to the top field ("Text to Display:") hit ctrl-A and ctrl-V to display it correctly in your email.

*This assumes you are using Outlook for sending your link. If not, you will need to open a new Outlook email or a Word document, or perhaps some other MS Office tool.

share|improve this answer

In corporate networks most IT Departments create shares using DFS Name Spaces, within DFS Shares you can right click on a folder and find its target.

The other method would be to see if the Share is published into Active Directory. The easiest way for other users to find shares without knowing the UNC path or File Server name / path.

If your sharing documents with large number of users, something like Microsoft SharePoint may be a better solution as offers a web interface (with WebDAV for UNC style access) and offers built in tools to alert other users to documents.

Hope This Helps.

share|improve this answer
1  
When I right click on my folders I don't see a "find target" option - what to you mean exactly? I mean, I can see the real path, it's not a mystery, I just want to be able to cut and past it and not type. As for Sharepoint, $50k in software isn't my ideal answer to "but can't I just cut and paste a path..." – Ernest Mueller Feb 14 '11 at 17:39

You can also right click the directory name in the computer directory view and select rename. This will give you access to copy the path.

share|improve this answer

In MS Windows Vista and above... Simply hold down the Shift key while right clicking the file in Windows Explorer. Select "Copy as Path". You may now paste the full UNC path to the file. Source and picture: How To Geek:

enter image description here

share|improve this answer
2  
That doesn't seem to work. When I do that it uses my mapped drive letter. – Al Everett Sep 28 '12 at 13:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.