So I am trying to set multiple variables with a For Loop in a Batch file. I know I need to use EnableDelayedExpansion 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.
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.
This is my original 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" >> %temp%\niresults.txt
If not exist %temp%\niresults.txt echo "Files not found"
set /p n1= < %temp%\niresults.txt
if exist C:\niresults.txt del /q C:\niresults.txt
)
I plan on using the variables in the following way.
wscript "FnR.vbs" "Find this" "Replace with this" !n1!
or
wscript "FnR.vbs" "Find this" "Replace with this" %n1% %n2% %n3%... etc
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 wscript "FnR.vbs" 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.
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 EnableDelayedExpansion)?
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.
I know I could back out and search a larger directory of C:\users 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.
notes.inifiles located in certain folders. But it is unclear why then1variable is assigned the output file's first line at every iteration of the loop.n1,n2etc. elsewhere, but there's onlyn1at the moment.