A-Z List


Pushd

Updated: April 17, 2012

Applies To: Windows Server 2008, Windows Vista

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

For examples of how to use this command, see Examples.

Syntax

pushd [<Path>]
Parameters

 

Parameter Description

<Path>

Specifies the directory to make the current directory. This command supports relative paths.

/?

Displays help at the command prompt.

Remarks

  • Every time you use the pushd command, a single directory is stored for your use. However, you can store multiple directories by using the pushd command multiple times.

    The directories are stored sequentially in a virtual stack. If you use the pushd command once, the directory in which you use the command is placed at the bottom of the stack. If you use the command again, the second directory is placed on top of the first one. The process repeats every time you use the pushd command.

    You can use the popd command to change the current directory to the directory most recently stored by the pushd command. If you use the popd command, the directory on the top of the stack is removed from the stack and the current directory is changed to that directory. If you use the popd command again, the next directory on the stack is removed.

  • If command extensions are enabled, the pushd command accepts either a network path or a local drive letter and path.

  • If you specify a network path, the pushd command temporarily assigns the highest unused drive letter (starting with Z:) to the specified network resource. The command then changes the current drive and directory to the specified directory on the newly assigned drive. If you use the popd command with command extensions enabled, the popd command removes the drive-letter assignation created by pushd.

Examples

The following example shows how you can use the pushd command and the popd command in a batch program to change the current directory from the one in which the batch program was run and then change it back:

@echo off
rem This batch file deletes all .txt files in a specified directory
pushd %1
del *.txt
popd
cls
echo All text files deleted in the %1 directory
Additional references

Command-Line Syntax Key

Popd

Tags :


Community Content

Batch 99
Work-around for using pushd without a path
Yes, apparently the directory parameter is no longer optional in order to have pushd record the current directory onto the pushd/popd stack.<br /><br />Work-around: Supply a "term" that always represents the current directory as the parameter to pushd. <br />Pushd will then push the current directory (as it should) onto the pushd/popd stack without changing the current directory, which is what you are trying to accomplish.<br />You can either use <b>pushd .</b> or <b>pushd %CD%</b><br /><br />C:\&gt;<b>pushd %CD%</b><br />C:\&gt;<b>D:</b><br />D:\&gt;<b>cd test</b><br />D:\test&gt;<b>popd</b><br />C:\&gt;<br /><br />Note that Command Extensions must be enabled in order to use %CD%. Command Extensions are enabled by default for the CMD.EXE shell (Windows XP and later, at least).<br /><br />The single period in <b>pushd .</b> also represents the current directory and is not dependent on the Command Extensions settings.<br />
Tags :

Dean Wiles
pushd doesn't appear to work without a path
<p>If you run pushd without a path it does not return to the original directory when you run popd. [&lt;Path&gt;] is documented as an optional parameter, but it does not appear to work correctly without a path specified.<br /><br />C:\&gt;pushd</p> <p>C:\&gt;cd C:\Windows</p> <p>C:\Windows&gt;popd</p> <p>C:\Windows&gt;rem note popd didn't change back when pushd not supplied an optional path</p> <p>C:\Windows&gt;cd \<br /></p> <p>C:\&gt;pushd C:\Windows</p> <p>C:\Windows&gt;popd</p> <p>C:\&gt;rem note pushd/popd only works if pushd supplied a path</p> <p> <br /> </p>
Tags : contentbug

Page view tracker