Reader Paul writes in with an interesting tip for using relative paths in a batch file: you can use a special code to represent the current path—useful for batch files on a Flash drive.
We've previously covered a similiar way to create shortcuts that run off a USB stick—but if you need the full path to the batch file regardless of the machine you plugged it into, you can substitute %~dp0 anywhere you want to use the current path of the batch file. Paul explains:
If you use "%~dp0" (sans quotes) in a batch file, this will point to the batch file's path. For example :
SET MAC=00:00:00:00:00:00 %~dp0mc-wol.exe %MAC%
MC-WOL.EXE is a wake-on-lan program, and this script wakes up the PC ready for the boss to remotely access his PC. I can get him to wake up his PC remotely without confusing the poor thing too much.
It's one of those tips that might not be useful for everybody, but it could really come in handy as part of your flash drive toolkit. For more, you can check out how FAST is a geeky command-line database, or how to kill multiple applications from the command line with a batch file. Thanks, Paul!
Got any useful batch-scripting wisdom to share? Tell us in the comments.