Windows Batch Script: get the script file name








syntax

  • ~ -- strip/trim quotes off
  • d -- drive
  • p -- path
  • n -- file name
  • x -- extension
  • f -- full path





examples

suppose I have a script file at C:\Users\WXYZ\Documents\test.cmd
@ECHO OFF
REM test.cmd
ECHO %~0

REM test
ECHO %~n0

REM .cmd
ECHO %~x0

REM C:\Users\WXYZ\test.cmd
ECHO %~dpf0

REM C:\Users\WXYZ\test.cmd
ECHO %~dpnx0

REM C:\Users\WXYZ\test
ECHO %~dpn0

REM C:\Users\WXYZ\
ECHO %~dp0





see also




No comments:

Post a Comment