222
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?

11
  • 16
    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
    Commented May 13, 2011 at 11:27
  • 1
    You can always browse to the unc path through run. Commented May 13, 2011 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. Commented May 13, 2011 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
    Commented May 13, 2011 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. Commented May 13, 2011 at 12:12

7 Answers 7

302

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>
12
  • 15
    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
    Commented Sep 6, 2012 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. Commented Apr 4, 2017 at 2:43
  • 1
    It's just worked for me in Windows 10, how odd. I did pushd \\ServerName\home\dir\dir2.
    – Diziet
    Commented May 20, 2017 at 14:36
  • 3
    Native and elegant, just a wonder. Works for Windows 10.
    – WesternGun
    Commented Jun 22, 2017 at 7:55
  • 1
    @kayleeFrye_onDeck I receive that same error once every available drive letter has been reserved. I used PUSHD on the same folder several times and filled "This PC" with letters B & D-Z. (C was my local drive but I don't know what A was. Possibly, it's a hidden partition but I couldn't find it.) The next time I tried to exact command that had just worked 15 times in a row, I got the same error you posted: ' ' CMD does not support UNC paths as current directories. Commented Aug 3, 2021 at 14:57
24

I use Git Bash to do this, since I already have it installed. As an added bonus, it also has better colors, lets me use ls, rm, etc., and uses the correct slash for paths.

enter image description here

4
  • You can also use backslashes if you escape them with backslashes: cd \\\\server\\share\\subdirectory
    – user121391
    Commented Jul 27, 2016 at 8:56
  • 1
    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
    Commented Jul 27, 2016 at 9:03
  • 1
    it does not work for me Commented Nov 6, 2018 at 9:46
  • Although Git Bash worked for me, it seemed slower than pushd/popd and CMD as used in the accepted answer for some reason. Though I also prefer Git Bash in general, and use it instead of CMD wherever possible.
    – AJM
    Commented Oct 23, 2023 at 18:33
13

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
  • 4
    This program is most awesome!
    – afrazier
    Commented May 13, 2011 at 16:37
  • 1
    i'm shocked by the screenshot, it exist! Commented Jun 21, 2012 at 11:01
  • remember to open the //drive and not a mapped version. It will fail on mapped.
    – twobob
    Commented May 4, 2017 at 14:04
12

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. :-)

4
  • 3
    Yes, but using net use will map that location to a network drive and that is not what I wanted. Commented Jan 28, 2013 at 12:36
  • 2
    @AndreasGrech, Actually pushd does that too.
    – Pacerier
    Commented Jan 24, 2015 at 6:48
  • This works well in Far+ConEmu, unlike pushd. Commented Jun 3, 2016 at 11:29
  • @Pacerier But pushd automatically selects a drive letter and disconnects the network drive when it’s no longer needed (after popd or exit).
    – Martin
    Commented Apr 12, 2019 at 15:26
5

If you're using XP you can have a look at this site https://web.archive.org/web/20150518102450/https://support.microsoft.com/en-us/kb/156276

(In case the link breaks again: Under Software\Microsoft\Command Processor: add a DWORD value called DisableUNCCheck if it doesn’t already exist and set it to 1.)

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) https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/pushd

3
  • The pages you linked seem like empty pages......
    – Pacerier
    Commented Jan 24, 2015 at 6:49
  • The links work here. Have you tried using https? Commented Jan 27, 2015 at 8:21
  • Seems to still work under windows 10 20H2
    – T S
    Commented Feb 10, 2021 at 8:48
-1

imho, the most elegant solution is to use mklink /D to create a symlink for the network path. if you use in a script you'll not have to find out which drive letter has been assigned.

1
  • 1
    The most elegant way to change directories (a read-only operation) is to modify the filesystem?  And where do you create the link?  \Temp?  You might not have write access to the current directory.  And what do you call the link?  What if there’s already a \Temp\somewhere that isn’t already a link to \\somewhere?  What if it’s a file that’s in use?  Etc…  How is this more elegant than pushd? Commented Jan 17, 2020 at 3:22
-4

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

2
  • 10
    Not very useful to a command line user. Commented Oct 20, 2012 at 5:17
  • 1
    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
    Commented Jan 5, 2018 at 22:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .