I use the free version of TimeSnapper (http://www.timesnapper.com) to help with reporting hours worked on various projects. The program saves a screen capture (png) at a user specified capture rate. To keep the logs manageable I have set the capture rate at one capture every 5 minutes. This gives me just over 100 captures every work day, which is a manageable number and doesn't take up too much disk space.
Recently the program was reset (by mistake) to its default of one capture every 5 seconds, giving me over 4000 captures every day! I now have several days of log files that I would like to thin down to one capture every 5 minutes, because the capture files are taking up too much space and I have to browse through too many files to find what I want.
Is there a way to write a batch file to thin these files down, leaving me with only one capture every 5 minutes? To complicate issues, TimeSnapper stops capturing when the computer is not in use (as when I'm in a meeting or at lunch), so it's not quite as simple as keeping every 60th file and deleting the rest. What does help is that the TimeSnapper file names reflect the capture time, e.g. 07.33.25.3325.png, and each day's capture files are in a different directory.
I haven't written a batch file in years (and even then I only wrote very simple ones), so the more detail the better my chances of success.
Here's the algorithm that occurred to me:
1. Copy the first file in the directory to another location.
2. Look for the file that was captured nearest to 5 minutes later, and copy it to the new location. If there's no file exactly 5 minutes later, select either the file just before or just after, depending on which is closer (I suspect this is the trickiest part).
3. Repeat till the end of the directory.
As what is probably a much simpler alternative, a batch file that would copy every 60th file would probably do, and I could manually check the large gaps and copy any additional files later if needed.
I'm using WinXP SP3.
Thanks.
Subsetting (thinning) files based on timestamp
Moderator: DosItHelp
Re: Subsetting (thinning) files based on timestamp
YossiD wrote:What does help is that the TimeSnapper file names reflect the capture time, e.g. 07.33.25.3325.png, and each day's capture files are in a different directory.
so the more detail the better my chances of success.
See here: viewtopic.php?f=3&t=6108
Tell us about the files.
Re: Subsetting (thinning) files based on timestamp
Welcome here, YossiD
Try this code and report the result. The ECHO command just display the MOVE command, so you must remove it in order to execute the MOVE.
Antonio

Code: Select all
@echo off
setlocal EnableDelayedExpansion
rem Initialize the desired lapse in seconds
set /A desiredLapse=5*60, lastTime=0
rem Process all .png files in current directory,
rem separating fields HH MM SS xxxx png into %%a to %%e tokens
for /F "tokens=1-5 delims=." %%a in ('dir /B *.png') do (
rem Get lapse in seconds of this file vs. last *selected* one
set /A "thisTime=((1%%a-100)*60+1%%b-100)*60+1%%c-100, thisLapse=thisTime-lastTime"
rem If it is larger than desired...
if !thisLapse! gtr %desiredLapse% (
ECHO move %%a.%%b.%%c.%%d.%%e "..\anotherDirectory"
set /A lastTime=thisTime
)
)
Try this code and report the result. The ECHO command just display the MOVE command, so you must remove it in order to execute the MOVE.
Antonio