Batch file command line arguments are parameter values submitted when starting the batch. They should be enclosed in quotes if they contain spaces. In a running batch file, the arguments are used for various purposes, i.e. redirection to :labels
, setting variables, or running commands.
The arguments are referred to in the batch file using %1, %2, ..., %9
.
@echo off
setlocal EnableDelayedExpansion
if not "%1"=="" (
set "dir=%~1" & set "file=%~2"
type !dir!\!file! | find /n /i "True" >nul^
&& echo Success! || echo Failure
)
exit /b
C:\Users\UserName> test.bat "C:\Temp\Test Results" "Latest.log"
Success!
Notes:
%~1
.^
, and there is a space before the character on the next line.