1.

Solve : Setting File Pointer to BOF from Batch File?

Answer»

I have searched the site using the string "dos batch bof eof" without success.

I have recently ARRIVED at batch files and am progressing with the help of some excellent web sites but I haven't found an answer to this one. Can anyone help please?

I have a batch file which copies some files as a backup measure. On completion it makes an entry in a log file. The most recent entry is PLACED at the end of the file. It would be better for me if it was at the BOF.

How do I do this please? I look forward to hearing from you - many thanks.

[glb]ScriptHam[/glb]       :-/Batch files don't have BOF and EOF pointers so you will have to do a little work around. In your .bat file, before it writes the entry to the LOGFILE, if exist logfile.txt ren logfile.txt logfile.old. After it writes the entry to logfile.txt copy logfile.old >>logfile.txt. Then del logfile.old. The newest entry should always be at the top.

Test the batch file FIRST, before applying it to your existing logfile. You can always delete any extra files but might not be able to recover your logfile if something goes awry. 
Thanks very much.
I can see that this will work. But at the moment it just KEEPS the most recent entry in the log file. I will need to troubleshoot it a bit. Will leave until Monday now.

Thanks once again for the prompt reply.

[glb]ScriptHam[/glb]It didn't quite work at first. What was needed was the concatenation script e.g.
Code: [Select]copy /B /Y H:\log.txt + H:\logold.txt H:\log.txt
in place of the redirection script
Code: [Select]copy /B /Y H:\log.txt >> H:\logold.txt
Other than that all went perfectly, thankyou very much.
Many thanks to you and my compliments of the season - have a good one.
Kind Regards
ScriptHam



Discussion

No Comment Found