title: Trying to use a batch file to work with filenames that have a forbidden character
body: <p>Okay, a brief explanation of what I am doing: I use Windows Media Center (Windows 7) to record Jeopardy every evening. I then use Handbrake to convert the .wtv files to .mkv files and then transfer them to my NAS so I can watch them later using Plex Media Server/Center. Rather than doing this "by hand", I'm trying to automate the process using a batch file as a scheduled task. Initially, I had set up a script so that I could right-click > Send To > convert.bat and it would initiate the command-line interface for Handbrake and convert the file, move the output to my NAS, and delete the original file (worked great).</p>
  
  <p>Now, what I'm doing is initiating the batch script as a scheduled task and looping through the contents of my "recorded tv" directory and looping through any .wtv files to convert/move/delete them.</p>
  
  <p>The problem lies in the fact that Windows Media Center correctly names the Jeopardy files with the "!" in them (Eg: Jeopardy!_KHQ_2012_12_04_21_12_12.wtv), which completely bricks my script. The "Send To" batch file worked great, but when I loop through the *.wtv files in the directory, it returns all the filenames with the "!" stripped out which means I can't do squat with them. Files without "!" do process without a hitch.</p>
  
  <p>Thanks in advance to anyone who can get me pointed in the right direction! (and if you happen to see any other areas where this script could be improved, that's fine too...)</p>
  
  <p>Here is the basic code that I am attempting to use:</p>
  
  <pre><code>@echo off
  
  setlocal ENABLEDELAYEDEXPANSION
  
  SET count=0
  SET getFolder=C:\Users\Public\Recorded TV\
  SET ripFolder=C:\Rips\
  SET putFolder=Z:\Videos\Recorded TV\
  
  FOR %%F IN ("%getFolder%*.wtv") DO (
  SET /A count=!count!+1
  
  REM DETERMINE OUTPUT FILENAME
  for /f "tokens=5,6,7,8,9,10 delims=\_" %%a in ("%%F") do (
      set show=%%a
      set station=%%b
      set year=%%c
      set month=%%d
      set day=%%e
      set hour=%%f
  
      REM GENERATE OUTPUT NAMING CONVENTION   
      set output=!show! s!year!e!month!!day! !hour!
  
  )
  
  REM PROCESS WITH HANDBRAKE CLI
  "C:\Program Files\Handbrake\HandBrakeCLI.exe" -i "%%F" -t 1 -c 1 -o %ripFolder%!OUTPUT!.mkv  -f mkv --deinterlace="fast" --crop 58:60:2:2 --strict-anamorphic  -e x264 -q 20 --vfr  -a 1 -E faac -B 160 -6 dpl2 -R Auto -D 0 --gain=0 --audio-copy-mask none --audio-fallback ffac3 -x ref=1:weightp=1:subq=2:rc-lookahead=10:trellis=0:8x8dct=0 --verbose=1
  
  REM MOVE CONVERTED FILE TO NAS
  copy "%ripFolder%!OUTPUT!.mkv" "%putFolder%"
  
  REM DELETE ORIGINAL
  del "%%F"
  
  REM DELETE LOCAL RIP
  del "%ripFolder%!output!.mkv"
  )
  
  echo %count% files processed
  
  pause
  
  ENDLOCAL
  </code></pre>