title: Batch file - cannot strip variable in sub routine
body: <p>I am struggling with a Windows batch file, which will be run at SERVER in intervals  and will evaluate all computers in network, then pull new and changed files to backup NAS device. I decided for such approach to have only 1 script to maintain against 150 backups on 150 computers.</p>
  
  <p>The problem I have is I need to extract computer NAME, which I store in .txt file as:</p>
  
  <p><strong>Name:   computername.domain.name</strong>
  to pure computer name:</p>
  
  <p><strong>computername.domain.name</strong></p>
  
  <p>I did this by pulling .txt file content into VARIABLE, then I strip first 9 characters off in SUB-routine <strong>:SUBfound</strong>:</p>
  
  <pre><code> setlocal enabledelayedexpansion
   for /L %%i in (0,1,255) do (call :SUBscan 192.168.79.%%i)
  
  :SUBscan ip
   echo|set /p dummyOutput="Scanning %1 ... "
   ping -n 1 -w 200 -4 %1 &gt;nul
   if %ERRORLEVEL% NEQ 0 (echo not a computer) else (
     if exist "\\%1\d$\DataFolder\" (call :SUBfound %1) else (call :SUBnotfound %1)
   )
   EXIT /B
  
  :SUBfound
   set targetname=&lt;backup_id.txt
   set "targetname=!targetname:~9!"
   ...other code
  EXIT /B
  </code></pre>
  
  <p>But targetname in :SUBfound does not evaluate:</p>
  
  <pre><code> echo !targetname!  --&gt;  echoes me:~9!
   echo %targetname%  --&gt;  echoes !targetname!
  </code></pre>
  
  <p>I know there must be something wrong with SET evaluation of variables in sub-routines, but cannot figure it out.</p>