Skip to content

Instantly share code, notes, and snippets.

@spajak
Last active June 11, 2019 16:44
Show Gist options
  • Save spajak/e7403d67a4d46186b39a6e8a673d538e to your computer and use it in GitHub Desktop.
Save spajak/e7403d67a4d46186b39a6e8a673d538e to your computer and use it in GitHub Desktop.
Batch script command line arguments variables
@echo off
rem Batch script (.bat or .cmd) command line arguments variables
rem %* - for all command line parameters (excluding the script name itself)
rem %0 - the command used to call the batch file
rem %1 - is the first command line parameter
rem %2 - is the second command line parameter, and so on till %9 (and SHIFT can be used for those after the 9th)
rem %~nx0 - the actual name of the batch file, regardless of calling method (some-batch.bat)
rem %~dp0 - drive and path to the script including trailing backslash (d:\scripts\)
rem %~dpnx0 - is the fully qualified path name of the script (d:\scripts\some-batch.bat)
set ZZZ=%~dp0
rem remove trailing backslash
set DIR=%ZZZ:~0,-1%
set FILE=%~nx0
echo Script filename: "%FILE%"
echo Script directory: "%DIR%"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment