1

I have a command that watches a certain folder for new files. These files are created by a video transcoder so are locked and keep growing in size till completion.

@echo OFF
:loop
if exist "E:\OUT\*.mxf" (
for %%i in ("E:\OUT\*.mxf") DO (
C:\bmx\bmxtranswrap -o "E:\DPP_create\DPP_OUT\%%~ni.mxf" -t as11op1a -y 09:59:50:00 --afd 10 "%%i"
ping -n 5 localhost >nul
del "%%i"
)
)
ping -n 5 localhost >nul
goto :loop

Is there a way to only pick up files which are fully completed (Windows unlocked)? At the moment the next command is tripping up as it is attempting to open an incomplete file.

Any advise? Thanks.

RJ Macready
  • 33
  • 1
  • 3

1 Answers1

0

As long as you are correct in that your transcoder has the file locked until it is complete, then the solution is actually simple.

Use redirection to test that you can open the file for writing, but don't modify it. Only process if the redirection succeeded.

Note:

  • You don't need your outer IF statement.
  • You can use an infinite FOR /L loop instead of a GOTO loop
  • I don't understand why you need a delay before your DEL, but I preserved it anyway.
@echo OFF
for /l %. in () do (
  for %%i in ("E:\OUT\*.mxf") do 2>nul( (call )>>"%%i" ) && (
    C:\bmx\bmxtranswrap -o "E:\DPP_create\DPP_OUT\%%~ni.mxf" -t as11op1a -y 09:59:50:00 --afd 10 "%%i"
    ping -n 5 localhost >nul
    del "%%i"
  )
  ping -n 5 localhost >nul
)
dbenham
  • 127,446
  • 28
  • 251
  • 390