r/Batch • • Dec 30 '21

Variables

can i make vars to set as certain values when called, like when the program is run, or when something is input into the prompt? or something like that?

edit: sorry i'm quite new to batch

edit: solved

0 Upvotes

3 comments sorted by

2

u/Shadow_Thief Dec 30 '21

You can use set to set variables, either by setting the value directly (set "variable_name=value") or by getting user input (set /p "variable_name=Prompt string: ").

https://ss64.com/nt/set.html

1

u/DatRetroBoi Dec 30 '21

thank you! i'm writing a program and im seeing if i can use variables to call errors

i do use set /p for prompt too, i thought it was just for user input

1

u/jimjamkiwi11 Aug 29 '24

Sorry for responding but set /p is used for user input but just set is for automatic variable setting for example:

Set /p "file=enter file: " -this will ask the user for a file and let the user type it.

Set "file=example.txt" this will automaticlcy set the file variable as example.txt

You can change the variables set.