Kit
Kit

Reputation: 1171

What does %~1 do in this batch file?

I found this code, but there are parts that I do not understand.

This is my code:

Main.bat:

@echo off
set "CallCount=0"
set "Mood="
set /P "Mood=Your mood is: "
call Receive.bat "%Mood%"
rem *Random stuff*
set "Food="
set /P "Food=The food you want is: "
call Receive.bat "%Food%"
set "CallCount="

Receive.bat:

@echo off  
set /A CallCount+=1           
if "CallCount"=="2" goto Call2   
if not "%~1"=="" echo %1     <----
*Random Stuff*                   |
goto :EOF                        |---What is %~1 doing in this area?
:Call2                           |
if not "%~1"=="" echo %1     <----
rem Commands for second call.

Edit: This is a file that uses the call command twice.

Upvotes: 29

Views: 55807

Answers (1)

Chris Noe
Chris Noe

Reputation: 37181

%1 is the first argument from the invoking command line. If the passed argument has quotes around it, %1 includes the quotes. Where as, %~1 provides the argument value with quotes removed.

Helpful reference here.

Upvotes: 69

Related Questions