title: Batch script fails with "The system cannot find the path specified"
body: <p>I have written the following batch script, which runs another batch script on a directory, or, with addition of a flag, on a directory tree and then on an equivalent directory or directory tree on a different drive (Z:). No matter which option I choose, it outputs the error "The system cannot find the path specified." It does do what it's supposed to if I do it on just one directory, even though it gives the error. It doesn't work successfully on a directory tree. I've run it without @echo off to try understand where its failing, without success. The directory which it's trying to change into does exist. </p>
  
  <pre><code>@echo off
  set origdir=%CD%
  if X%~f1==X (
  echo Please input a directory.
  goto done
  )
  
  chdir /d %~f1
  for %%X in (myotherscript.bat) do (set FOUND=%%~$PATH:X)
  if not defined FOUND (
      echo myotherscript is not in your PATH
      )
  if X%2==X/R (
  goto recursive
  ) else ( goto single )
  
   :recursive     
  for /d /r %%G in (.) do call myotherscript
  echo Z:%~p1
  chdir /d "Z:%~p1"
  for /d /r %%G in (.) do call myotherscript
  goto ended
  
  :single
  call myotherscript
  echo Z:%~p1
  chdir /d "Z:%~p1"
  call myotherscript
  goto ended
  
  :ended
  chdir /d origdir
  goto done
  
  :done
  pause
  </code></pre>
  
  <p>Here is "myotherscript" Yes, purge does exist.</p>
  
  <pre><code>@echo off
  if exist "D:\path\to\purge.bat" (
      call purge
      for %%f in (*.log.*) do call :renameit "%%f"
      for %%f in (*.drw.*) do call :renameit "%%f"
      for %%f in (*.asm.*) do call :renameit "%%f"
      for %%f in (*.prt.*) do call :renameit "%%f"
      goto done ) else (
      echo Purge does not exist.
      goto done )
  
  :renameit
  ren %1 *.1
  
  :done
  </code></pre>
  
  <p>Any help would be appreciated.
  Thanks</p>