I’m looking at a batch file which defines the following variables:
set _SCRIPT_DRIVE=%~d0 set _SCRIPT_PATH=%~p0
- What do
%~d0or%~p0actually mean? - Is there a set of well-known values for things like current directory, drive, parameters to a script?
- Are there any other similar shortcuts I could use?
The magic variables
%n contains the arguments used to invoke the file:%0is the path to the bat-file itself,%1is the first argument after,%2is the second and so on.Since the arguments are often file paths, there is some additional syntax to extract parts of the path.
~dis drive,~pis the path (without drive),~nis the file name. They can be combined so~dpis drive+path.%~dp0is therefore pretty useful in a bat: it is the folder in which the executing bat file resides.You can also get other kinds of meta info about the file:
~tis the timestamp,~zis the size.Look here for a reference for all command line commands. The tilde-magic codes are described under for.