title: Windows Batch Script - Read file names into variables
body: <p>I am trying to convert files (movies) in a directory, one by one. Each new, converted file needs a new file name assigned - the old one with a new extension.</p>
  
  <p>I've tried the below to read the source file, strip off the extension and assign a new one:</p>
  
  <pre><code>@echo off
  setlocal DisableDelayedExpansion
  cd \target_dir
  for %%x in (*) do (
    echo %%x
    set source=%%x
    echo Source #%source%#
    set target=%source:.mpg=%
    echo Target #%target%#
    transcode %source% %target%.mp4
  )
  </code></pre>
  
  <p>Unfortunately, this is not working. As the output shows, I am not even managing to copy the current file into the variable "source":</p>
  
  <pre><code>E:\target_dir&gt;..\test.bat
  movie1.mpg
  source ##
  target ##
  movie2.mpg
  source ##
  target ##
  </code></pre>
  
  <p>I googled around and thought I'd have found the right syntax, but that doesn't appear to be it. Thanks for any help!</p>