Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 645 Vote(s) - 3.44 Average
  • 1
  • 2
  • 3
  • 4
  • 5
For /L loop with padded number

#1
I wish to make a nested for loop in order to process some files. I have looked extensively for the solution, and have found many similar versions, but since this is my first time I am having trouble combining methods to do what I want.

Basically - I want a FOR /L loop that cycles through a range of padded numbers from 001 to say 500.

I know I can specify a range (1,1,500), but obviously not as (001,001,500). How can I add the 00, and then subsequently when %%a is >9, just a 0? I imagine this is as a sting but perhaps there is another way?

My code as I wished it to be (obviously wrong):

@echo off
for %%a in (001,001,500) do (
echo %%a
for %%s in (control scenario) do (
echo %%s
svic_ensemble.exe 28009_Trent_at_Colwick.cal Trent_%%s_%%a.txt 28009_Trent_at_Colwick.txt Trent_%%s_%%a.out
)
)
pause


Many thanks

Ed

Reply

#2
The easiest way of getting zero-padding is to pad with plenty of zeroes and then use a substring:

set Number=1
set PaddedNumber=000000%Number%
set PaddedNumber=%PaddedNumber:~-3%

You can adapt this for use in the loop, although you'll need delayed expansion:

setlocal enabledelayedexpansion
for /l %%a in (1, 1, 500) do (
set num=000%%a
set num=!num:~-3!
for %%s in (control scenario) do (
svic_ensemble.exe 28009_Trent_at_Colwick.cal Trent_%%s_!num!.txt 28009_Trent_at_Colwick.txt Trent_%%s_!num!.out
)
)
Reply

#3
You can solve it with string manipulations.
First prefix the number with two zeros and then take only the last three characters.

setlocal EnableDelayedExpansion
for /L %%n in (1 1 500) do (
set "num=00%%n"
set "num=!num:~-3!"
echo !num!
)
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through