batch-file Creating Files using Batch


One useful feature of batch files is being able to create files with them. This section shows how to create files using batch code.


  • echo (type here whatever you want in the to be) >> (filename)
  • echo (variable name) >> (filename)


If a file exists, > will overwrite the file and >> will append to the end of the file. If a file does not exist, both will create a new file.

Also, the echo command automatically adds a newline after your string.


echo 1 > num.txt
echo 1 > num.txt 
echo 2 >> num.txt 

will create the following file:


Not this:

1 1 2


1 2

Furthermore, you cannot just modify a single line in a text file. You have to read the whole file, modify it in your code and then write to the whole file again.