Here's a nice blog post on this...

Silly batch file tricks, redirecting stdout into an evironment variable and %~dp0

But just for my own reference the cryptic looking character sequence resolves to the path to the batchfile you are running.

So if you put the following in a batch file, no matter what directory you are in when you run it, it will print the directory the batch file is in, and do a directory listing.

echo Batch file path is %~dp0
dir %~dp0