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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:18:51+00:00 2026-05-25T19:18:51+00:00

I am using a for loop and constructing names of env variables ( like

  • 0

I am using a for loop and constructing names of env variables ( like abc%%i , where i is the loop variable ) that are to be read , and use delayed expansion to print out their values (assuming these env variables have already been set ) ..

echo is dos provides the facility to mention the field width of the variable to be printed out like echo %x:~-8% will right justify the value of x and the field width will be 8 ..

But since i am using delayed expansion , !abc%%i:~-8! does not seem to be working .

Any ideas as to how to set field width while using delayed expansion ,??

Happiness
Deepak

  • 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-25T19:18:52+00:00Added an answer on May 25, 2026 at 7:18 pm

    I don’t know who told you that %x:~-8% would pad out your variable but they’re wrong, at least in the version of cmd that I’m using (XP).

    That construct will simply give tou the last 8 characters if the variable is 8 or more. If it’s less than 8, you’ll get the variable itself, sans padding.

    If you want it padded, you can use something like:

    set y=        %x%
    echo %y:~-8%
    

    And, as can be seen from this script, !abc%%i:~-8! works just fine once you realise that you’re responsible for the padding:

    @setlocal enableextensions enabledelayedexpansion
    @echo off
    for /f %%i in ('echo 1 ^&^& echo 92') do (
        set var%%i=        %%i
        echo !var%%i:~-8!
    )
    echo.=====
    set var
    endlocal
    

    This outputs:

           1
          92
    =====
    var1=       1
    var92=       92
    

    as you would expect.

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

Sidebar

Related Questions

I want to create a read-eval-print loop using flex/bison parser. Trouble is, the flex
I just designed a simple For Loop using window form application. I would like
I have the following C for loop using bit shifts, that I want to
I have following foreach-loop: using System.IO; //... if (Directory.Exists(path)) { foreach(string strFile in Directory.GetFiles(path,
I am using XmlReader in .NET to parse an XML file using a loop:
I am running a windows service and using a loop and Thread.Sleep to repeat
How do I simplify this templated vector initializer loop using lambdas or some kind
Is there any way to clean up this type of loop using LINQ? List<Car>
I cannot seem to access the context object using a loop context is set:
first time posting here. I'm using a loop to create 3 buttons, but my

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.