"Offering free computer help, hints, and tips to the Internet populace." Now with over 3,820 tips!

Windows XP and DOS

Remembering Directories (PUSHD and POPD)

SUMMARY: Use the PUSHD and POPD commands to remember directory names in DOS with Windows XP.


 

When writing a batch file for Windows XP, have you ever had the need to switch to a different directory, perhaps to output logging or debug information, and then immediately switch back to the current directory?

Instead of storing the directory name in an environment variable, you can use the built-in PUSHD and POPD commands.

PUSHD places the current directory in an internal memory FILO (first-in, last-out) stack. It then jumps to the specified directory after the PUSHD command.

POPD pops the last directory out of the internal memory stack and goes to that directory.

Here's an example sequence of DOS commands:

C:\Downloads>pushd c:\temp

C:\temp>pushd c:\windows

C:\WINDOWS>pushd c:\

C:\>popd

C:\WINDOWS>popd

C:\TEMP>popd

C:\Downloads>

If you try to perform a POPD when no directory remains in the stack, no error is shown; you will remain in the current directory.

Note that PUSHD can also be used with network paths as well as directories. In this case, Windows will temporarily create a drive letter that points to the network directory and store that drive letter in the stack. When you perform a POPD, the temporary drive will be eliminated. Windows looks for unused drive letters Z: on down.



Print This Tip

Get E-Mail When New Tips are Online

Return to the Windows XP and DOS page.

 


New in MalekTips:

RSS Feeds- Subscribe!

You want the latest tech tips and tricks in your e-mail Inbox - FREE? Type your e-mail address below and click 'Get Tips!'.
 


( sample / details )
( opt-out instructions )