Showing posts with label commandline. Show all posts
Showing posts with label commandline. Show all posts

Wednesday, July 8, 2009

Use Relative Paths in Your Batch Files

If you haven't come across this already, this could be handy in the future. Simply use the special variable "%~dp0" without the quotes to refer to the current path where the batch file is located. This is different from using "." or "%CD%", which refers to your current path, i.e. the location that you are calling the batch file from.

For example, say you have this batch file in C:\TEMP\cur.bat

@echo off

echo Batch file location: %~dp0
echo Your current path: %CD%

If your prompt is currently sitting at C:\, and run the batch file with the command "TEMP\cur.bat", the output would look like this:

Batch file location: C:\Temp\
Your current path: C:\