Changing the current directory to a UNC path in DOS
Monday, February 18th, 2008A useful tip in DOS and for those batch files is how to change the current directory to a network drive. You can use the NET USE command to map a network drive, but that requires knowing an available drive letter… The commands PUSHD and POPD allow you to immediately jump to the UNC path, temporarily mapping the first available drive letter. Use the command as follows:
PUSHD \\SERVERNAME\SHARE
The current directory will be changed to the route directory of a temporarily mapped network drive pointing at the share mentioned in the command. Use POPD on its own to unmap the drive and return to wherever you were before the PUSHD command was used. If you used PUSHD again before POPD then you begin to stack the drive mappings, and you simply POPD for each one of them when you’re done. Run PUSHD without any parameters to see the current details of the stack.