Batch files can use modifiers to get information about the file and its current path as well as passed in parameters.

This example uses a batch file named “test.bat” that exists in “C:\Test”.
To get the current drive letter:

@ECHO OFF
SETLOCAL

:: Get drive letter
ECHO %~d0

:: Get full filepath
ECHO %~f0

:: Get file name
ECHO %~n0

:: Get file extension
ECHO %~x0

ENDLOCAL

will return

C:
C:\Test\test.bat
test
.bat

You can modify these parameters to examine arguments as well.

References:
Microsoft Technet

Leave a Reply

You must be logged in to post a comment.