Even though PowerShell is actually becoming the de-facto standard for scripting, there are still a whole lot of batch-scripts which are used for every day tasks and need to be maintained. And event there are always new things to discover.
To pass parameters to a batch-file isn’t really something new. With %1, %2 and so on you can access those parameters within the script. Noteworthy might be the fact, that %1 is the first parameter, while %0 is the name of the script itself.
What I didn’t know so far where some extra variables like %~f0, %~d0, %~p0 … as well as combinations like %~dp0; but then again, I’m not really so much into batch-scripting.
Here is a little overview about what I recently discovered, maybe it helps for someone else:
Description | Example | |
%~f | complete path inlc. filename | C:\winnt\system32\x.cmd |
%~d | drive letter | C |
%~p | path | \winnt\system32 |
%~dp | complete path | C:\winnt\system32 |
%~sp | short path | C:\Progra~1\Intern~1 (for C:\Programme\Internet Explorer) |
%~x | file extension | .cmd |
%~nx | filename incl. extension | x.cmd |
%~sx | short file extension | .doc (for .document) |
%~a | file attributes | |
%~t | date and time of a file | |
%~z | size of a file |