Trying to create a batch to convert .WTV files to mpg files. The code below I want to run once a night to convert the daily recordings for use on my media server. The section I am concerned about syntax is the for loop line. I only want to run the script on the files that have not been converted and moved. I cant delete the original in case and error occurs. The last move loop is to get all the files it couldn’t move on the first try.
the input files look like : show.wtv
the output in the file is show.wtv.mpg (which I’m ok with)
I am not sure how to write that for loop to get the desired functionality. Any help is appreciated.
Original idea came from 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"
for %%f in (%recordedtv%*.wtv) Do If Not Exist "%destfolder%%%f.mpg" (
%wtvconv% "%%f" "%%f.dvr-ms"
%ffmpeg% -y -i "%%f.dvr-ms" -vcodec copy -acodec copy -f dvd "%%f.mpg"
del "%%f.dvr-ms"
move "%%f.mpg" %destfolder%
)
for %%f in (%recordedtv%*.mpg) Do move "%%f" %destfolder%
UPDATE: Ended up 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"
for %%f in ("%recordedtv%*.wtv") do If Not Exist "%destfolder%%%~nxf.mpg" (
%wtvconv% "%%f" "%%f.dvr-ms"
%ffmpeg% -y -i "%%f.dvr-ms" -vcodec copy -acodec copy -f dvd "%%f.mpg"
del "%%f.dvr-ms"
move "%%f.mpg" "%destfolder%"
)
for %%f in ("%recordedtv%*.mpg") Do move "%%f" "%destfolder%"
If you are planning to add other parts to paths stored in variables, do not store the paths with the surrounding quotation marks. Just leave the double quotes out or put them like this:
That way you’ll be able to concatenate the paths with names/masks without causing syntax errors. Note that your paths are not delimited with double quotes, so you’ll need to delimit them where they are evaluated, as necessary, so, for instance, the
forloops would look like this:Pay attention to other places as well. For example, in the
movecommand in your script the target path will also have to be delimited:As for file existance check, that is done with the
if existcommand:The
target_filebit can be a file, a mask, or a directory (in the latter case it should end with\).UPDATE
I think I can see now a particular problem with your script. This part
is wrong in that it puts your destination folder and the full path to a
.wtvfile together and uses the resulting string as a single path. So"%destfolder%%%f"gets evaluated to something like this:I’m only not sure about extra quotation marks, but that is not the point here. I guess you can see the main problem. To resolve it, you need to extract only file name and extension from
D:\Recorded TV\somename.wtv.mpg, which is done using the combined~nxspecifier (nstanding for ‘name’ andxfor ‘extension’):(Note that the folder paths should still be stored without surrounding double quotes in order for them to be evaluated correctly in complex expressions.)