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 6176699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:08:49+00:00 2026-05-24T00:08:49+00:00

I am writing a batch file to run on Windows server 2008 R2, it

  • 0

I am writing a batch file to run on Windows server 2008 R2, it has a for loop in it and no matter how many tutorials I read online and try, it won’t run the for loop.

echo "Starting blur detection..."
if not exist %root%\output mkdir output
set tempnum = dir root | find /i "file"
set num = tempnum-5
for /l %idx in (0, 1, num) do (
   %root%\blurDetection.exe %root%\%img%__%idx%.tif %root%\output
   echo "blurDetection" %idx " of " %num )

Windows powershell says “idx was unexpected at this time.”
Any suggestions?

EDIT: Actually I think this line is causing the problem, I don’t think it is getting and integer value in return.

set tempnum = dir root | find /i "file"
  • 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-24T00:08:50+00:00Added an answer on May 24, 2026 at 12:08 am

    (added after initial post) Oh and I missed the biggest issue. Which is indeed this line:

    set tempnum = dir root | find /i "file"
    

    You mean to capture the output of dir, right? This can, AFAIK only be done inside for, unless you can live with outputting into a file and using that as input later.

    Syntax is in such a case:

    FOR /F ["options"] %variable IN ('command') DO command [command-parameters]
    

    Note: those are not backticks.

    Best explanations for NT scripting for: http://www.robvanderwoude.com/ntfor.php

    One more note: since you appear to rely on the file name as some number, I suspect that dir /b would be the better choice. Plain dir will also output date and file size etc …


    IIRC names of for variables cannot have more than one letter. Also, inside script files (as apposed to the command line) those variables look like this:

    %%i
    

    Besides, the

    set num=tempnum-5
    

    should probably be

    set /a num=%tempnum%-5
    

    Another question about find is whether you meant to use findstr. Too little context, but findstr seems more natural.

    From for /?:

    FOR %variable IN (set) DO command [command-parameters]
    
      %variable  Specifies a single letter replaceable parameter.
      (set)      Specifies a set of one or more files.  Wildcards may be used.
      command    Specifies the command to carry out for each file.
      command-parameters
                 Specifies parameters or switches for the specified command.
    
    To use the FOR command in a batch program, specify %%variable instead
    of %variable.  Variable names are case sensitive, so %i is different
    from %I.
    

    Note in particular these two statements:

    • %variable Specifies a single letter replaceable parameter.
    • To use the FOR command in a batch program, specify %%variable instead of %variable.

    Another peculiar feature of for loops is that you can split your input and tokens will get assigned to variables in alphabetical order. So inside a for %a ... tokens would get assigned to %a, %b and so forth …set tempnum = dir root | find /i “file”

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a batch file for windows command prompt, I want to loop through
When writing a batch file to automate something on a Windows box, I've needed
I am writing a batch file script using Windows command and want to change
I'm writing a Windows batch file and want to copy something to the desktop.
I have a variable define as: set filePath=.\file.txt I'm writing a windows batch file.
Howdy, I'm writing a batch script that will run on a Windows XP machine.
When I'm writing a batch file to run automatically, how do I write it
I'm writing a windows batch file and need to check whether the print exists
I am writing a simple batch file and i get this The syntax of
I am writing a batch script which I wish to open a file and

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.