if statement - Batch Syntax For Loop If Exists -
if statement - Batch Syntax For Loop If Exists -
trying create batch convert .wtv files mpg files. code below want run 1 time night convert daily recordings utilize on media server. section concerned syntax loop line. want run script on files have not been converted , moved. cant delete original in case , error occurs. lastly move loop files couldn't move on first try.
the input files : show.wtv
the output in file show.wtv.mpg (which i'm ok with)
i not sure how write loop desired functionality. help appreciated.
original thought came http://ireckon.net/2009/10/converting-wtv-to-mpg-in-windows-7/
@echo off set recordedtv="d:\recorded tv\" set destfolder="d:\videos\recorded tv\" set ffmpeg="d:\tv converter\ffmpeg\ffmpeg.exe" set wtvconv="c:\windows\ehome\wtvconverter.exe" %%f in (%recordedtv%*.wtv) if not exist "%destfolder%%%f.mpg" ( %wtvconv% "%%f" "%%f.dvr-ms" %ffmpeg% -y -i "%%f.dvr-ms" -vcodec re-create -acodec re-create -f dvd "%%f.mpg" del "%%f.dvr-ms" move "%%f.mpg" %destfolder% ) %%f in (%recordedtv%*.mpg) move "%%f" %destfolder% update: ended using this
@echo off set "recordedtv=d:\recorded tv\" set "destfolder=d:\videos\recorded tv\" set ffmpeg="d:\tv converter\ffmpeg\ffmpeg.exe" set wtvconv="c:\windows\ehome\wtvconverter.exe" %%f in ("%recordedtv%*.wtv") if not exist "%destfolder%%%~nxf.mpg" ( %wtvconv% "%%f" "%%f.dvr-ms" %ffmpeg% -y -i "%%f.dvr-ms" -vcodec re-create -acodec re-create -f dvd "%%f.mpg" del "%%f.dvr-ms" move "%%f.mpg" "%destfolder%" ) %%f in ("%recordedtv%*.mpg") move "%%f" "%destfolder%"
if planning add together other parts paths stored in variables, not store paths surrounding quotation marks. leave double quotes out or set them this:
... set "recordedtv=d:\recorded tv\" set "destfolder=d:\videos\recorded tv\" ... that way you'll able concatenate paths names/masks without causing syntax errors. note paths not delimited double quotes, you'll need delimit them evaluated, necessary, so, instance, for loops this:
for %%f in ("%recordedtv%*.wtv") ... ... %%f in ("%recordedtv%*.mpg") ... pay attending other places well. example, in move command in script target path have delimited:
move "%%f.mpg" "%destfolder%" as file existance check, done if exist command:
if exist target_file ( ... // whatever need in case file exists ) the target_file bit can file, mask, or directory (in latter case should end \).
update
i think can see particular problem script. part
for %%f in (%recordedtv%*.wtv) if not exist "%destfolder%%%f.mpg" is wrong in puts destination folder , total path .wtv file , uses resulting string single path. "%destfolder%%%f" gets evaluated this:
"d:\videos\recorded tv\d:\recorded tv\somename.wtv.mpg" i'm not sure quotation marks, not point here. guess can see main problem. resolve it, need extract file name , extension d:\recorded tv\somename.wtv.mpg, done using combined ~nx specifier (n standing ‘name’ , x ‘extension’):
for %%f in ("%recordedtv%*.wtv") if not exist "%destfolder%%%~nxf.mpg" (note folder paths should still stored without surrounding double quotes in order them evaluated correctly in complex expressions.)
syntax if-statement batch-file for-loop
Comments
Post a Comment