Ways to create a file with the echo command:
echo. > example.bat (creates an empty file called "example.bat")
echo message > example.bat (creates example.bat containing "message")
echo message >> example.bat (adds "message" to a new line in example.bat)
(echo message) >> example.bat (same as above, just another way to write it)
Output to path
A little problem you might run into when doing this:
echo Hello how are you? > C:\Users\Ben Tearzz\Desktop\example.bat
(This will NOT make a file on the Desktop, and might show an error message)
But then how do we do it? Well it's actually extremely simple... When typing a path or file name that has a space included in it's name, then remember to use "quotes"
echo Hello how are you? > "C:\Users\Ben Tearzz\Desktop\example.bat"
(This will make a file on MY Desktop)
But what if you want to make a file that outputs a new file?
echo message > file1.bat > example.bat
(This is NOT going to output:
"message > file1.bat" to example.bat
Then how do we do this?
echo message ^> file1.bat > example.bat
(This will output:
"message > file1.bat" to example.bat
Same goes for other stuff in batch
If you haven't learned what variables and statements are, then you most likely won't understand the following: click here to learn about variables | click here to learn about "if" statements
Variables:
set example="text"
echo %example% > file.bat
(This will output "text" to file.bat)
if we don't want it to output "text" but just plain %example% then write:
echo ^%example^% > file.bat
(This will output "%example%" to file.bat)
else statements:
else = ||
if ^%example^%=="Hello" echo True || echo False > file.bat
(This will output:
if %example%=="Hello" echo True
to output the whole line we write:
if ^%example^%=="Hello" echo True ^|^| echo False > file.bat
This will output:
if %example%=="Hello" echo True || echo False
If the variable is equal to "Hello" then it will say "True", else it will say "False"