1.

Solve : Batch file to search directories for log files based on timestamp?

Answer»

Anyone have a batch file to search for all log files in SEVERAL DIRECTORIES based on a timestamp?

For example I want to FIND all log files in all the directories under foo that INCLUDE the log for let's say 2pm. The log files have timestamp 1:42pm, 1:57pm, 2:13pm, etc. So you would return the file with the last timestamp of 2:13pm. You would then go on to search the next directory in the same way.

Thanks,
srizzo

Code: [Select]@echo off
:start
set /p add=what time are you looking for?
if "%add%"="" echo enter time please && goto start
dir c:\foo\*.txt /t:c /s | find "%add%"
you'll have to be exact on the time. Unless you want to code in tolerances.

FBThat's the thing, the log file won't have an exact time that matches the user input. The batch file NEED to find the file where the user input would be the last file less than the timestamp of the log file.

For example user inputs 2:13pm

foo.log 1:33pm
foo1.log 1:55pm
foo2.log 2:21pm

The batch file would need to return foo2.log file since the user input falls between 1:55pm and 2:21pm.


Quote from: fireballs on January 08, 2009, 10:24:06 AM

Code: [Select]@echo off
:start
set /p add=what time are you looking for?
if "%add%"="" echo enter time please && goto start
dir c:\foo\*.txt /t:c /s | find "%add%"
you'll have to be exact on the time. Unless you want to code in tolerances.

FB


Discussion

No Comment Found