PUSHD

Change the current directory/folder and store the previous folder/path for use by the POPD command.

Syntax
      PUSHD [drive]path

      PUSHD

Key
   drive  The drive to switch to
   path   The folder to make 'current' (UNC names accepted)

If the drive is not specified, the current drive will be assumed.
If neither drive nor path are specified PUSHD will just display a list of previous pathnames, you may switch back to any of these by using POPD one or more times.
If the path specified does not exist, PUSHD will return %errorlevel% =1

Run as Admin

When a batch script is 'Run as Admin' in Vista or Windows 7, the current directory will be set to C:\windows\system32\.
Using the following pushd command at the start of the script will restore the normal current directory.

This works by setting the current directory to the location of the batch script, using the %0 parameter

pushd "%~dp0"

UNC Network paths

When a UNC path is specified, PUSHD will create a temporary drive map and will then use that new drive.
The temporary drive letters are allocated in reverse alphabetical order, so if Z: is free it will be used first.

Examples

C:\demo> pushd \work 
C:\work> popd
C:\demo> pushd "F:\monthly reports" F:\monthly reports> popd
C:\demo>

PUSHD is an internal command. If Command Extensions are disabled the PUSHD command will not accept a network (UNC) path.

#Ah, push it - push it good
Ah, push it - p-push it real good# ~ Salt 'N' Pepa

Related:

CD - Change directory
CMD - UNC options
PROMPT - Display the level of the PUSHD stack ($+)
Powershell: Push-Location - Push a location to the stack (pushd)
Powershell: cd - Jump to the previous working directory
Equivalent bash command (Linux): pushd - Save and then change the current directory


© Copyright SS64.com 1999-2013
Some rights reserved