1.

Solve : Appending text to a file?

Answer»

:question
Hi everyone,

In my batch FILE I have created a text file USING the command
Code: [Select]copy nul C:\test.txtI am also adding text to the file using the command
Code: [Select]echo Backup completed at %time:~0,8% > "C:\test.txt"I want to add further lines of text to the file, but whenever I echo SOMETHING out to the file it overwrites the previous echo. How can I append the echo to the previous one in the file?Quote

:question
Hi everyone,

In my batch file I have created a text file using the command
Code: [Select]copy nul C:\test.txtI am also adding text to the file using the command
Code: [Select]echo Backup completed at %time:~0,8% > "C:\test.txt"I want to add further lines of text to the file, but whenever I echo something out to the file it overwrites the previous echo. How can I append the echo to the previous one in the file?


Use two of > .


Example:
Code: [Select]echo Backup completed at %time:~0,8% >>"C:\test.txt"

One ">" MEANS redirect output the following file, and if it already exists then OVERWRITE it.

Two ">", as in ">>" means redirect output to the following file and if it already exists, append to it.

Additionally, here is something to try:
With > or >> , it is implicit that if the file to write to does not already exist, then create it.
Thus, your "copy nul.... " line is not necessary.

I hope this helps.


Discussion

No Comment Found