C:\> cd \\somewhere
'\\somewhere'
CMD does not support UNC paths as current directories.

What I usually do to get around this is to map that directory to a network drive and then I could easily access it from the command prompt.

But is there an easier way on how to get around this?

  • 12
    which windows do you use? If it's Windows 7, you've powershell preinstalled on your system. Powershell supports unc-paths and cmd-commands (with few exceptions). – wullxz May 13 '11 at 11:27
  • You can always browse to the unc path through run. – Not Kyle stop stalking me May 13 '11 at 11:45
  • 1
    @wullxz: cheers, I didn't know you could browse UNC paths with PowerShell. @kyle: That's actually a valid answer according to my question :) But I want to access it from a command line environment. Will modify my question to make this more clear. – Andreas Grech May 13 '11 at 12:09
  • If your problem is that you need to work just from the command line, you can map the network drive with the 'net' command: net use x: \\computer name\share name – Al Crowley May 13 '11 at 12:11
  • 1
    @Aleister Crowley: Yes I know, but I'm asking if there's an easier way that doesn't involve mapping a network drive. – Andreas Grech May 13 '11 at 12:12
up vote 182 down vote accepted

If you use pushd and popd instead of cd you won't get that UNC error.

pushd <UNC path> will create a temporary virtual drive and get into it.
popd will delete the temporary drive and get you back to the path you were when you entered pushd.

Example:

C:\a\local\path> pushd \\network_host\a\network\path

U:\a\network\path> REM a temporary U: virtual drive has been created

U:\a\network\path> popd

C:\a\local\path> REM the U: drive has been deleted

C:\a\local\path>
  • 10
    Using pushd creates a drive mapping to the network share and then changes into a path relative to the share it creates. popd disconnects the share. – Dov Sep 6 '12 at 15:55
  • 2
    This didn't work for me on Windows 10. C:\WINDOWS\system32>pushd \\some\network\path ' ' CMD does not support UNC paths as current directories. – kayleeFrye_onDeck Apr 4 '17 at 2:43
  • 1
    It's just worked for me in Windows 10, how odd. I did pushd \\ServerName\home\dir\dir2. – Diziet May 20 '17 at 14:36
  • 3
    Native and elegant, just a wonder. Works for Windows 10. – WesternGun Jun 22 '17 at 7:55
  • Is there any trick to make it work when the share credentials don't match the machine's user credentials? – Perkins Mar 7 at 0:51

Kliu's "ContextConsole Shell Extension" (aka Open Command Prompt) says it, "can even open directories from network paths (UNC paths)" (from an Explorer window).

http://code.kliu.org/cmdopen/

enter image description here

  • 3
    This program is most awesome! – afrazier May 13 '11 at 16:37
  • 1
    i'm shocked by the screenshot, it exist! – LiuYan 刘研 Jun 21 '12 at 11:01
  • remember to open the //drive and not a mapped version. It will fail on mapped. – twobob May 4 '17 at 14:04

I use Git Bash to do this, since I already have it installed.

enter image description here

As an added bonus:
It also has better colors, let's me use ls, rm, etc., and uses the correct slash for paths. :P

  • You can also use backslashes if you escape them with backslashes: cd \\\\server\\share\\subdirectory – user121391 Jul 27 '16 at 8:56
  • Also, if you try to use tab completion with computer names, the shell might lock up for some time until the names are resolved. – user121391 Jul 27 '16 at 9:03
  • it does not work for me – KansaiRobot Nov 6 at 9:46

I also hit the UNC problem with C:\> cd \\somewhere in a C program. Found this page and learnt about the net command: net use x: \\computer name\share name and used it successfully! Thanks to all who post their experiences for others to learn from. :-)

  • 1
    Yes, but using net use will map that location to a network drive and that is not what I wanted. – Andreas Grech Jan 28 '13 at 12:36
  • 1
    @AndreasGrech, Actually pushd does that too. – Pacerier Jan 24 '15 at 6:48
  • This works well in Far+ConEmu, unlike pushd. – Dzmitry Lahoda Jun 3 '16 at 11:29

If you're using XP you can have a look at this site http://support.microsoft.com/kb/156276

There is a registry value that you need to add, log out, log in again ... and now your cmd.exe does support UNC-Paths. It seems to me that you still can't cd to the path, but you can use it in other commands like dir, copy ...

An alternative might be using the pushd command, that will let you switch to the share (i guess by assigning it a temporary drive letter) http://support.microsoft.com/kb/317379

  • The pages you linked seem like empty pages...... – Pacerier Jan 24 '15 at 6:49
  • The links work here. Have you tried using https? – BigBlackDog Jan 27 '15 at 8:21

You can use the HttpFileServer application, it' over windows, very light and very easy to configure , it allow you to share a network folder UNC ( \server\share ) with HTTP protocol and the HTTP link can be used in any HTML page

http://www.rejetto.com/hfs/

it's amazing

  • 8
    Not very useful to a command line user. – Isaac Rabinovitch Oct 20 '12 at 5:17
  • I agree that this is an amazing piece of software, but how can it be used to get around the fact that the CMD window app does not handler UNC? – Jay Elston Jan 5 at 22:02

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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