1

Hi I wonder how to do print out a list from 1 to 200 with 3 digit format. I can print from 1 to 200 but dont know how to do the format thing. Please help

FOR /L %%A IN (1,1,200) DO (ECHO %%A)

2 Answers 2

4

You have to set a variable with enough zeros on the front, then take the last few characters to give the correct range. Delayed expansion means that the variables used will not be evaluated only once when the do is encountered, but every time the variable is used.

This example will print 1-200

@echo off
setlocal enabledelayedexpansion

for /l %%a in (1,1,200) do (
set test1=00%%a
set test2=!test1:~-3!
echo !test2!
)
Sign up to request clarification or add additional context in comments.

Comments

3
@echo off
title Counter
SET /A XCOUNT=0

:loop
SET /A XCOUNT+=1
IF "%XCOUNT%" == "301" (
    GOTO end
) ELSE (
    IF %XCOUNT% LSS 100 (
        IF %XCOUNT% LSS 10 (
            echo 00%XCOUNT%
            GOTO loop
        ) ELSE (
            echo 0%XCOUNT%
            GOTO loop
        )
    ) ELSE (
    echo %XCOUNT%
    GOTO loop
    )
)
:end

pause

I know its lengthy, but hey, it works!

1 Comment

+1, for the work, but the answer from Sean Cheshire is obviously better

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.