Yummy PushPops

push and popd | Admin ArsenalSometimes you miss the most useful features of a program for a long time just because, well… you’re human. That’s how it was with me and the Windows command line pushd & popd commands.

It was many years into their existence before I heard of them, and I was ecstatic. I was constantly writing batch files for building and deploying my projects and it involved a lot of switching between directories. These commands really were a godsend.

The way they work is you call pushd to change a directory (like you would use cd). Then, you would later call popd to return to the directory where you had called pushd. These can be nested, so that you can pop a bunch of directories off in the order that they were pushed. Push and pop come from the programming terms for working with a stack, which is how these commands work. They’re like working with a stack of directories, where you push one onto the top and then pop it off revealing the one below to be popped off itself.

It turned annoying commands like this:
cd SetupLib\bin\x86\Release
_do  some stuff_
cd ..\..\..\

into this
pushd SetupLib\bin\x86\Release
_do some stuff_

All those little .. identifiers are prone to bugs, especially when the directory structure changes, trying to remember how many you need.

Now, if only a batch file would return to the original directory when you cancel in the middle (like they typically do on UNIX) then I’d be a really happy camper.