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

8 Answers8

314

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>

AJM
  • 500
evanmcdonnal
  • 3,308
25

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

reformed
  • 113
Dan
  • 890
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

therube
  • 1,476
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. :-)

grawity
  • 501,077
6

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

T S
  • 253
0

Yes, there's a much easier way using pushd:

pushd "\\server\share\path"

This automatically maps the UNC path to an available drive letter (like Z:) and changes to that directory. When you're done, use popd to return to your original location and unmap the drive.

For WSL paths specifically, I've created a batch script that automates this process: goWSLPath.cmd

Usage:

goWSLPath.cmd /home/user/project

This script:

  1. Auto-detects your WSL distribution
  2. Converts POSIX paths to UNC format (\\wsl$\Ubuntu-22.04\home\user\project)
  3. Uses pushd to map and navigate there automatically

Key advantages of pushd over manual mapping:

  • No need to specify drive letters
  • Automatic cleanup with popd
  • Works with any UNC path, not just network drives
  • Built into Windows, no additional tools needed

The script handles the common Unicode encoding issues when detecting WSL distributions and provides proper error handling for missing paths or inactive WSL instances.

Foad
  • 892
  • 4
  • 19
  • 54
-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.

-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

Salman
  • 1