Programming Field

Pushd - DOS/Command Prompt Reference

[Windows NT series] Changes the current directory to the specified directory. This change can be restored by using Popd command.


pushd <directory>


No options are available except for the directory name.

Specifies the directory path to change to. The path can be on the different drive to the current drive, and in this case the current drive will also change.


Usage of Pushd 1

About Pushd

By using Pushd and Popd, you can change the current directory temporarily to work on something. Pushd can be called multiple times and each directory changes can be restored with corresponding Popd calls (stack structure).

In batch files, if executing Pushd under Setlocal localized environment, and calling Endlocal (or exiting the batch program) to exit the localized environment, the current directory will be the one before calling Setlocal, but the calls of Pushd will not be reset; the current directory will only be rewritten to the before one, meaning not that Popd is performed for Pushd calls. For example if calling Pushd twice, and calling Popd after Endlocal calls, the current directory will be the first Pushd directory.

[Extensions] If Extensions are enabled, the following behaviors are applied as well as Chdir.

  • If the case of the name specified at <directory> differs from the one from the actual directory name, the actual name will be used for the current directory. If Extensions are disabled, the current directory is set to the name <directory> as-is.
  • Even if the path <directory> includes space characters, you do not need quotations (" ") for the path; Pushd interprets the path correctly. If Extensions are disabled, quotations are required for the path including spaces.

Using network path

Usage of Pushd 2

[Extensions] If Extensions are enabled, and a network path is specified to <directory>, Pushd temporarily maps ‘\\computer-name\\share-name’ included by the network path to a network drive, and changes the current directory to the path in its drive. This network drive will be unmapped when Popd is called or the current session (prompt) exits.

* To map to a network drive not temporarily, use Net command. And, if accessing the network path requires authentication, it is necessary to be authenticated in advance by using Net command or etc.
* Subst command can also map a network path to a drive, and its drive remains until system reboot even if the session exits, but its Subst drive will not be treated as a network drive.


Sample 1

pushd D:\Temp

Changes the current directory to D:\Temp temporarily, executes ‘foo.exe’, and restores the directory by calling Popd.

Sample 2

pushd \\myserver\files\20120922
copy /Y data.csv E:\

[Extensions] Moves to the network path ‘\\myserver\files\20120922’ temporarily, copies the file ‘data.csv’ in that path to ‘E:\’, and restores the current directory by calling Popd. While execution, Pushd maps ‘\\myserver\files’ to a network drive temporarily, and changes the current directory to ‘x:\20120922’ (where x is a drive letter available on Pushd). After this, Popd unmaps the network drive after restoring the current directory.

See also