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.
%0 is the name of the batch file. %~n0 Expands %0 to a file Name without file extension.
The %~dp0 Variable. The %~dp0 (that's a zero) variable when referenced within a Windows batch file will expand to the drive letter and path of that batch file. The variables %0-%9 refer to the command line parameters of the batch file.
%%i is simply the loop variable. This is explained in the documentation for the for command, which you can get by typing for /? at the command prompt.
Running shift once in a batch file will make "%1" value to be the second argument, "%2" becomes the third, and so on. It's useful for processing command line arguments in a loop in the batch file. Show activity on this post. %1 is the first argument given, %2 the second.
%1
is the first argument form 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With