pushd/popd and UNC paths

June 23rd, 2008

According to the help for pushd:

Stores the current directory for use by the POPD command, then changes to the specified directory.

Generally you use it like:

C:\>pushd c:\windows\system32
c:\Windows\System32>rem blah
c:\Windows\System32>popd
C:\>

Not very exciting.

However pushd has a little known feature; you can dynamically map UNC paths:

C:\>pushd \\server\netlogon
Z:\>rem blah
Z:\>popd
C:\>

In this case pushd finds the first available drive letter (working backwards from Z:), maps a network drive, and changed the current working directory to it.  popd then unmaps the network drive.

This makes is a very handy tool for batch scripting, including in login scripts.

Leave a Reply