Do not batch move files that are currently written

Posted on

Problem :

I need to periodically move some tv records, however it is possible that one of them is still recorded during moving. now i need a batch utility that can detect if a file is already completely written or there is still data written into it. if there is still data written to it, the moving of this file shall be skipped. the problem is, that currently e.g. move command simply moves what’s already there, the recording software (windows media center) doesn’t seem to really lock the file to prevent such things. so, how to move only finished recordings?

Solution :

If Media Center will not lock it, I guess it’s hard to know. Slightly different approach, but it might fit your purposes, you can use robocopy to move files that are older that 1 day.

robocopy [src] [dest] /mov /MINAGE:1

The other way to do this is to check if anything is being recorded and only move files when nothing is. This can be done very easily by determining whether or not ehrec.exe is running:

tasklist /FI "IMAGENAME eq ehrec.exe" 2>NUL | find /I /N "ehrec.exe">NUL
if "%ERRORLEVEL%"=="0" echo Something being recorded

Leave a Reply

Your email address will not be published. Required fields are marked *