title: Change a Variable in a For Loop in a Batch file
body: <p>So I am trying to set multiple variables with a For Loop in a Batch file. I know I need to use <code>EnableDelayedExpansion</code> but I have tested out several different methods and so far nothing seems to work. Also, this will generally be run as a domain user that does not have a user folder on the computer. </p>
  
  <p>The end goal is to collect the file path for notes.ini for each user directory. Originally I would repeat a section for each folder and change the variable to n1 then n2 then n3. I am trying to compact this and allow this file to handle any number of user folders. I need to be able to call each path individually latter int the batch file, so currently I have each path written to a txt file then the txt file parsed into a variable. </p>
  
  <p>This is my original code:</p>
  
  <pre><code>SETLOCAL EnableDelayedExpansion
  for /D %%x in ("C:\Users\*") do (
  if exist %temp%\niresults.txt del /q %temp%\niresults.txt
  dir "%%x\AppData\Local\lotus\Notes\*.*" /L /A /B /S|Find "notes.ini" &gt;&gt; %temp%\niresults.txt
  If not exist %temp%\niresults.txt echo "Files not found"
  set /p n1= &lt; %temp%\niresults.txt
  if exist C:\niresults.txt del /q C:\niresults.txt
  )
  </code></pre>
  
  <p>I plan on using the variables in the following way.</p>
  
  <pre><code>wscript "FnR.vbs" "Find this" "Replace with this" !n1!
  </code></pre>
  
  <p>or </p>
  
  <pre><code>wscript "FnR.vbs" "Find this" "Replace with this" %n1% %n2% %n3%... etc
  </code></pre>
  
  <p>FnR.vbs is setup to accept and process parameters 3 through x in a loop so the number of parameters doesn't matter too much; however, FnR does take a little while to run. I thought about including the <code>wscript "FnR.vbs"</code> in the loop but currently I have to call it 4 times for each file location and will do that if I have to but it will slow everything way down.</p>
  
  <p>So is there a way to get this to work so that each path will be in a different variable or change the name of the txt file for each time the loop is run? or omit the txt file and dump the output directly into a variable (I think this might be what I need most to get it to work with <code>EnableDelayedExpansion</code>)?</p>
  
  <p>The easiest solution would be, is it possible to change  n1 to n2 at the second iteration of the loop and n3 at the 3rd and so on. </p>
  
  <p>I know I could back out and search a larger directory of <code>C:\users</code> for the files but with the amount of user data on most of the machines in my environment that would make the file take longer to run that the actions it would replace.</p>