# What is the correct way to escape UNC paths?

Let's say there is a file \\server-42\tmp\dir\test.txt. When my plugin tries to execute this command via system() it triggers an error:

cd "\\server-42\tmp\dir" && git ls-files --error-unmatch --full-name test.txt


The error is E484: Can't open file C:\Users\foo\AppData\Local\Temp\blah.tmp.

The directory is produced by shellescape(fnamemodify(filepath, ':h'), where filepath is the full path to file. The file is produced by shellescape(fnamemodify(filepath, ':t').

How can I get this to work?

• that will be hardly possible, since I believe Windows cmd does not support UNC paths at all (Try cd \\server-42\temp\dir) You would have to map the network drive to drive letter and work with that I believe – Christian Brabandt Feb 14 '18 at 10:57
• Windows supports \\hostname\path (for almost as long as I can remember...I'm dating myself)...they call it a 'network path', though. :P I haven't tried to use them in Vim, though. – B Layer Feb 14 '18 at 11:13
• Windows does, but not the command line subsystem of Windows. However, it seems like you might be able to use pushd and popd instead – Christian Brabandt Feb 14 '18 at 12:04
• @ChristianBrabandt My bad. My eyes skipped right over 'cmd'. – B Layer Feb 16 '18 at 1:50
• @ChristianBrabandt Good to know that cmd does not support UNC paths at all. Also, pushd seems to work – thanks! I'll be happy to accept if you add it as an answer. – Andy Stewart Feb 16 '18 at 11:44

The problem you are encountering is, that the commandline subsystem on Windows does not support UNC paths. (Try running cmd.com and then cd \\server\path\to\dir and notice the error message CMD does not support UNC paths as current directories.)
That leaves you with mapping the path to a temporary drive letter using net use or instead of using cd use pushd instead, which basically maps your path to a temporary drive letter so you'll be able to access that file afterwards easily.
Using pushd will temporarily create a drive mapping to the network share and then change into a path relative to it. popd then will disconnects the share and return to your previous current directory.