Current directory manipulation in batch files

Posted: (EET/GMT+2)

 

Sometimes, you want to write (DOS) batch files (those with .BAT or .CMD extensions) to automate certain tasks. I today learned a neat little trick using the %CD% environment variable. This variable always holds the current directory where the batch file is. You can use this to manipulate paths, or save the path for later use into another environment variable.

Of course, since Windows XP you can also use the pushd and popd (push and pop directory) commands to save and restore the current directory/path. I learned these commands at the time I was still using 4NT, but now with Windows XP and later, these commands are part of the CMD.EXE command interpreter.