Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7092925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:22:31+00:00 2026-05-28T08:22:31+00:00

Trying to create a batch to convert .WTV files to mpg files. The code

  • 0

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%"
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T08:22:31+00:00Added an answer on May 28, 2026 at 8:22 am

    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:

    ...
    set "recordedtv=D:\Recorded TV\"
    set "destfolder=D:\Videos\Recorded TV\"
    ...
    

    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 for loops would look like this:

    for %%f in ("%recordedtv%*.wtv") do ...
    ...
    for %%f in ("%recordedtv%*.mpg") do ...
    

    Pay attention to other places as well. For example, in the move command in your script the target path will also have to be delimited:

    move "%%f.mpg" "%destfolder%"
    

    As for file existance check, that is done with the if exist command:

    if exist target_file (
    ...    // do whatever you need to do in case the file exists
    )
    

    The target_file bit 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

    for %%f in (%recordedtv%*.wtv) Do If Not Exist "%destfolder%%%f.mpg"
    

    is wrong in that it puts your destination folder and the full path to a .wtv file together and uses the resulting string as a single path. So "%destfolder%%%f" gets evaluated to something like this:

    "D:\Videos\Recorded TV\D:\Recorded TV\somename.wtv.mpg"
    

    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 ~nx specifier (n standing for ‘name’ and x for ‘extension’):

    for %%f in ("%recordedtv%*.wtv") Do If Not Exist "%destfolder%%%~nxf.mpg"
    

    (Note that the folder paths should still be stored without surrounding double quotes in order for them to be evaluated correctly in complex expressions.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a batch file that will convert an Excel file to
I'm trying to create batch file which should have this commands: cd c:\Program files\NuSMV\2.5.2\bin\
I'm trying to create a batch file that will run Doug Cockford's JSMin against
Trying to create several layers of folders at once C:\pie\applepie\recipies\ without using several different
I am trying to create a batch file that removes tel: from a number
I am trying to create a batch script for my Windows machine that loops
I'm trying to create a batch script that will delete all sub directories which
In relation to this previous question I am trying to create a batch file
I am trying to create a simple batch file that will replace a line
I'm trying to create a right-click context menu command for compressing JavaScript files with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.