title: Rename files "The syntax of the command is incorrect" .bat
body: <p>I am trying to remove a string from multiple file names in multiple directories. This is the file as with a few files being created so that I can check what values are actually being SET.</p>
  
  <p>When I  get to the <code>rename</code> at the very bottom I get an error:</p>
  
  <blockquote>
    <p>The syntax of the command is incorrect.</p>
  </blockquote>
  
  <p>I don't see anything amiss in the <code>_intf</code> and <code>_fnlf</code> text files that get created. Is there some trick to using variables as the file path in a rename?</p>
  
  <pre><code>@ECHO off
  
  echo Delete dir.txt?
  PAUSE
  
  del dir.txt
  del item.txt
  del file.txt
  
  ::paths for all directories in root (where filerename.bat is run)
   ::get root dir path
   SET "_c=%CD%"
   SET /A "counter=0"
   ::get dir list and concats root dir path before
   FOR /F "tokens=*" %%A in ('DIR /on /b /a:d /p %svnLOCAL%') DO ( 
      SET "_dirp=%_c%\%%A"
      CALL :sub1
      SET /A "_counter+=1"
   )
  
  ::finds each file in dir
  :sub1
   ::make file to check dir path
   ECHO "%_dirp%" &gt; dir.txt
   FOR /F "tokens=*" %%B in ('DIR /b %_dirp%') DO (
    ECHO "%%B" &gt; item.txt
    SET "_item=%%B"
    SET "_filep=%_dirp%\"
    CALL :sub2 %%~nB
  PAUSE
   )
   ECHO "%_counter%"
  EXIT /b 0
  
  ::builds file paths
  :sub2
   set "str=%*"
   set "str=%str:[1]=%"
   SET "_intf=%_filep%%_item%"
   SET "_fnlf=%_filep%%str%"
   CALL :sub3
  EXIT /b 0
  
  ::Renames each file
  :sub3
   ECHO "%_intf%" &gt; _intf.txt
   ECHO "%_fnlf%" &gt; _fnlf.txt
   ren "%_intf%" "%_fnlf%.jpg"
  EXIT /b 0
  </code></pre>