Software >> OS >> Windows >> Command Line >> Batch >> How to obtain the file name, extention, drive letter, path and fullpath of the running script

 

SPECIAL VARIABLES

Variable Purpose

%0

The script filename as it was called.
E.g. if we ran script.bat as script.  If we ran it as script.bat, it will return script.bat
 
%~d0 The drive letter of the running script
%~p0 The path part of the running script
%~n0 The file name part of the running script
%~e0 The file extention part of the running script
%~f0 The full path of the running script

 

EXAMPLE SCRIPT

d:\home\bin\script.bat

@echo off
echo.
echo This running script information :-
echo.
echo drive     %~d0
echo path      %~p0
echo filename  %~n0
echo extension %~x0
echo fullpath  %~f0

 

EXAMPLE OUTPUT