View last modified log file

Does this look familiar? The good old directory full of log files in your face.

If you spend a lot of time sifting & sorting through log files to find the last modified file for inspection, then this tip might make your day.

I've been searching for a program, that has the following features

* Automatically open the last modified file in a directory
* Provide custom code highlighting
* Real time log viewing
* Cost nothing

Unfortunately, i could not find such a program, but when i was about to give up, i thought of a cheap trick.

I can write a batch file that parses a directory for the last modified file, and open it using my favourite editor/viewer.

Heres how we can achieve it.

Create a batch file with the following contents

@echo off
for /f "tokens=* delims= " %%a in ('dir /b /o:-d C:\Temp\*.log') do (
baretail.exe %%a
goto :eof

Log directory: C:\Temp\
Log file extention: *.log
dir /b: filename only listing
/o:-d: orders by date descending
log viewer: baretail.exe

I know you can just keep a explorer window open, sort your files by date, click refresh, and double click your file, but thats about 4 clicks, including the click to find your window when it loses focus.

Create this shortcut in your taskbar, and you can do it with 1 click, and at the same time, your desk space will be less cluttered, and more memory friendly.

Note: Baretail, is a free real time log viewer that allows custom highlighting. Although it is not freeware, it is a lite version which does not expire.



  1. I tried with winword.exe as the output file..but its not getting generated..plz advice

    below is the code which i have edited...

    @echo off
    for /f "tokens=* delims= " %%a in ('dir /b /o:-d C:\Documents and Settings\Administrator\Desktop\Jay\*.txt') do (
    winword.exe %%a
    goto :eof


  2. Hi Jayadev,

    i dont have access to a windows machine atm to test this out, but try getting rid of the spaces in your file path.

    replace your "documents and settings" with the dos 6 syntax > "docume~1". you could also try to wrapping your path in quotes.


Comments are open to all, please make it constructive.