Display text from .txt file in batch file

Deniz Zoeteman picture Deniz Zoeteman · May 24, 2009 · Viewed 106.2k times · Source

I'm scripting a big batch file.

It records the date to a log.txt file:

@echo off
echo %date%, %time% >> log.txt
echo Current date/time is %date%, %time%.
@pause
exit

It can record it several times, on several lines. Now what I want to do is that the batch file file shows the last recorded date/time from the log.txt file.

How?

Answer

viraptor picture viraptor · May 24, 2009
type log.txt

But that will give you the whole file. You could change it to:

echo %date%, %time% >> log.txt
echo %date%, %time% > log_last.txt
...
type log_last.txt

to get only the last one.