Browse an UNC path using Windows CMD without mapping it to a network drive
Solution 1
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>
Solution 2
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.
Solution 3
Kliu's "ContextConsole Shell Extension" (aka Open Command Prompt) says it, "can even open directories from network paths (UNC paths)" (from an Explorer window).
Solution 4
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. :-)
Solution 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
Andreas Grech
+++++[>+++++[>++++<-]<-]>>+++.--..++++++. Contactable at $(echo qernfterpu#tznvy?pbz | tr ?a-z# .n-za-m@)
Updated on September 18, 2022Comments
-
Andreas Grech over 1 year
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?
-
wullxz almost 13 yearswhich 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).
-
Supercereal almost 13 yearsYou can always browse to the unc path through run.
-
Andreas Grech almost 13 years@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.
-
Rachit_Goyal almost 13 yearsIf 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
-
Andreas Grech almost 13 years@Aleister Crowley: Yes I know, but I'm asking if there's an easier way that doesn't involve mapping a network drive.
-
Rachit_Goyal almost 13 years@Andreas Grech: I thought that was likely the case, that's why I put it as a comment rather than an answer.
-
Kellen Stuart over 7 yearsUse powershell and it works
-
Cristian Ciupitu about 6 yearsRelated: How do you handle “CMD does not support UNC paths as current directories”? from Server Fault
-
Franklin Yu over 5 years@wullxz That deserves to be an answer. Look at the answers below; "ContextConsole Shell Extension" and "Git Bash" get several upvotes. I think PowerShell is better than third-party solutions.
-
wullxz over 5 years@FranklinYu added the answer
-
Steve Rindsberg almost 3 yearsIf you mean to browse in Windows explorer you can start an Explorer instance pointed at the desired drive with: start \\servername\sharedpath
-
-
afrazier almost 13 yearsThis program is most awesome!
-
LiuYan 刘研 almost 12 yearsi'm shocked by the screenshot, it exist!
-
Dov over 11 yearsUsing
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. -
Isaac Rabinovitch over 11 yearsNot very useful to a command line user.
-
Andreas Grech over 11 yearsYes, but using
net use
will map that location to a network drive and that is not what I wanted. -
Pacerier over 9 years@AndreasGrech, Actually
pushd
does that too. -
Pacerier over 9 yearsThe pages you linked seem like empty pages......
-
BigBlackDog over 9 yearsThe links work here. Have you tried using https?
-
Dzmitry Lahoda almost 8 yearsThis works well in
Far
+ConEmu
, unlikepushd
. -
user121391 almost 8 yearsYou can also use backslashes if you escape them with backslashes:
cd \\\\server\\share\\subdirectory
-
user121391 almost 8 yearsAlso, if you try to use tab completion with computer names, the shell might lock up for some time until the names are resolved.
-
kayleeFrye_onDeck about 7 yearsThis didn't work for me on Windows 10.
C:\WINDOWS\system32>pushd \\some\network\path
' ' CMD does not support UNC paths as current directories.
-
GreXLin85 about 7 yearsremember to open the //drive and not a mapped version. It will fail on mapped.
-
Diziet almost 7 yearsIt's just worked for me in Windows 10, how odd. I did
pushd \\ServerName\home\dir\dir2
. -
WesternGun almost 7 yearsNative and elegant, just a wonder. Works for Windows 10.
-
Jay Elston over 6 yearsI 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?
-
Perkins about 6 yearsIs there any trick to make it work when the share credentials don't match the machine's user credentials?
-
Shicheng Guo over 5 yearsworks perfect. and I need check how to put these kind of directory into perl script.
-
Jacob Krall over 5 years@Perkins: I was able to use runas.exe to run PowerShell as the other user
-
Perkins over 5 years@JacobKrall That would work if another user has the proper credentials. If it's a totally different set of credentials, use cmdkey.
-
KansaiRobot over 5 yearsit does not work for me
-
Martin about 5 years@Pacerier But
pushd
automatically selects a drive letter and disconnects the network drive when it’s no longer needed (afterpopd
orexit
). -
Kimmi almost 5 yearsWorks perfect. I was using the sshfs, if it will automatically create a virtual drive (Z, in my case). And access normally to Z like the ones did in C or D.
-
G-Man Says 'Reinstate Monica' over 4 yearsThe 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 thanpushd
? -
T S about 3 yearsSeems to still work under windows 10 20H2
-
jackhab almost 3 yearsI also noticed that if you pushd to the same location it will map a new network drive again and again and if you close the shell and open a new one calling popd will not, of course, be able to unmap them so one could end up having a bunch of unused network drives.
-
Engineer Toast almost 3 years@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.
-
kayleeFrye_onDeck over 2 years@EngineerToast thanks for the heads up! Very possible that was the problem for me.