views:

503

answers:

1

Hello

I have alot of log files which need searching for certain strings and was wondering if I could make a batch file to automate this job for me? All I need it to do is locate the most recent log in a certain directory then search for the string in that file.

I have found the below code on this website which works great to open the most recent log file but unfortunatly I dont know enough about batch programming to amend the code to search for the string and display the line.

for /f "usebackq delims=" %%i in (`dir /b /o-d`) do @call "%%i"&goto :eof

Any help would be much appreciated.

+6  A: 

Add a findstr to the end:

or /f "usebackq delims=" %%i in (`dir /b /o-d`) do findstr searchforthisstring %%i

What this is doing is searching for "searchforthisstring" the files found by

dir /b/o-d

Which list files (/b = simply name not any other info and /o-d reverse date order

Preet Sangha