pushd and popd for Setting the Current Directory to a UNC Path

Recorded on November 17th, 2016

I learned a cool trick today. I needed to switch the current directory in a Windows command prompt window to a server folder at a UNC (Universal Naming Convention) path in the form of \\Server\Volume\File. But the Windows “cmd” command line window only accepts cd commands with a drive letter when you’re giving an absolute path. If you try to put a UNC path in there, you’ll get an error message.

The workaround is to use
pushd and popd when you need to set the current directory to a UNC path. It maps a temporary virtual drive letter to that path and sets the current directory to it. Then you go about your business at the command line. When you’re done, you type popd, which will delete the temporary drive mapping and get you back to where you were.

blog comments powered by Disqus