Batch Script Appending to Files
Appending to Files
In Batch Script, writing content to files is also done with the help of the >>
double redirection filter. This filter can be used to add any output to a file.
note
Learn more about redirection in our Redirection Operators Chapter
Example
The following is a simple example of how to create a file using the redirection command to add data to files.
@echo off
echo "This is the directory listing of C:\ Drive">C:\new.txt
dir C:\>>C:\new-file.txt
The first echo command is used to create the file using the single redirection command, while the dir
command is sent to the file using the double redirection filter.
"This is the directory listing of C:\ Drive"
Volume in drive C is Windows10_OS
Volume Serial Number is E12C-3F45
Directory of C:\
12/22/2015 09:02 PM <DIR> 01 - Music
06/14/2015 10:31 AM <DIR> 02 - Videos
09/12/2015 06:23 AM <DIR> 03 - Pictures
12/17/2015 12:19 AM <DIR> 04 - Software
12/15/2015 11:06 PM <DIR> 05 - Studies
12/20/2014 09:09 AM <DIR> 06 - Future
12/20/2014 09:07 AM <DIR> 07 - Fitness
09/19/2015 09:56 AM <DIR> 08 - Tracking
10/19/2015 10:28 PM <DIR> 09 – Misc