So my friend was asking me about batch files today and I showed him some that I use and the log text files that they create. He asked me if there was a way to append the information to the top of the file within batch so that instead of having to scroll to the bottom in notepad etc that the most recent info was at the top of the file instead of the bottom.
I told him that getting to the bottom of the log file is just a simple key stroke combination of the CTRL + END key in which I showed him how that worked in notepad to get there without having to manually scroll. He seemed determined to challenge if it could be done in batch, but I have not seen it done so I figured I'd post here on his behalf to see if it can be done in just pure batch.
The only way i can see it done would be to run a script that would read the log file from the last line and then write that as the first line in the new ( newest to oldest ) log order in which it would read in the last line and remove this and then work its way to the last line of the original log file and end when no more data was left and the end result would be the original log file reversed.
Personally I have always just used CTRL + END key to get there quickly, but he does have a interesting question that now has me interested as well.
Normally I just send information appending to the log file such as
@echo. Backup Started on %date% at %time%>>Z:\Backup.log
cls
@echo. Processing Backup
c:
cd\.
cd data
xcopy *.* z:\data\*.* /s/d/y >>Z:\changes.log
@echo. Backup Ended on %date% at %time%>>Z:\Backup.log
cls
@echo. Backup Complete
pause
with the xcopy or robocopy routine in between the logging which writes what files were copied or updated with new to changes.log file since I also send the output from xcopy or robocopy to file vs display through the appending redirection to file. During this process leading up to that I have a Processing Backup displayed and when its done a CLS followed by a Backup Completed with a pause statement so I have to close it out when manually run, however the pause is removed from the batch file that is in the startup folder as for I just want it to run and match files and close on its own.