Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6725269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:47:15+00:00 2026-05-26T09:47:15+00:00

So I am trying to set multiple variables with a For Loop in a

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:47:16+00:00Added an answer on May 26, 2026 at 9:47 am

    Alternatively to using ‘indexed’ variables, you could use a ‘list’ variable for collecting all the names in the loop and then just reference it later in the command line that calls the VB script. Something like this:

    SETLOCAL EnableDelayedExpansion
    set nlist=0
    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
    set nlist=!nlist! "!n1!"
    if exist C:\niresults.txt del /q C:\niresults.txt
    )
    :: now all the names are in the %nlist% variable,
    :: so you can call the VB script like this
    wscript "FnR.vbs" "Find this" "Replace with this" %nlist%
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have multiple preg match expressions, and I'm trying to use each to output
I'm trying to get a node-set from a xsl variable for calculating. But my
I am trying to output a set of data, and I have, due to
I am trying to set a couple of global variables in a subreport so
I'm trying to write a trigger in MySQL and I need to set the
I'm quite a noob at Jquery but I'm trying to set a variable based
In other words I have a thread that starts and calls waitHandle.Set() multiple times.
I am trying to set git on my Mac Os Snow Leopard 10.6.7 but
I am just starting out with backbone and am trying to set up a
I have a variable in XSLT called variable_name which I am trying to set

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.