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 can switch back to any of these by using POPD one or more times.
The number of pushed directories can be displayed on the command line with PROMPT $+
If the path specified does not exist, PUSHD will return %errorlevel% =1
When a batch script is 'Run as Admin', 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
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.
Current directory was changed = 0
Directory does not exist or is not accessible or bad switch given = 1
C:\demo> pushd \work C:\work> popd
C:\demo> pushd "F:\monthly reports" F:\monthly reports> popd
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
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