i'm creating a counter in cmd

Hewlett-packard Pavilion dv6-2190us note...
December 7, 2010 at 05:27:44
Specs: Windows Vista
this is what the file i want should look like

count.txt_____


0000000
0000001
0000002
0000003
0000004
0000005
0000006
0000007
0000008
0000009
0000010
...
-----------------------

what would the code be for this?


See More: im creating a counter in cmd

Report •


#1
December 7, 2010 at 07:23:13
It depends how large the numbers are. You could prefix the number with a "1", increment and the remove the "1", like so:

set cnt=0000000

set /a cnt=(1%cnt% + 1) 
set cnt=%cnt:~1%

You just have to be a little bit careful.


Something like this could also do it:


http://judago.webs.com/content/Scri...


Report •

#2
December 7, 2010 at 07:54:21
@echo off & setlocal enabledelayedexpansion
for /l %%a in (1 1 10) do echo %%a
pause


change the number 1 1 and 10. 1 is from where to start, 2nd 1 is the interval and last 10 is the last point.

Subhash Chandra.


Report •

#3
December 7, 2010 at 16:52:02
thank you

how about something like this

i'd also like the program / batch to stop at

how do i go about that?
9999999


Report •

Related Solutions

#4
December 7, 2010 at 16:55:34
oh ok cool thanks
this worked real well :)
yeah it make sense now
but it didn't do what i wanted it to do... :P

it just counted number didn't keep the zero's in the whole the whole equation :P


Report •

#5
December 7, 2010 at 23:27:52
The same basic idea as the first part of #1. It just won't work if you have to use numbers larger than 2^31-1 for 32bit or 2^63-1 for 64 bit systems.


@echo off & setlocal enabledelayedexpansion
for /l %%a in (10000000 1 19999999) do (
   set num=%%a
   echo !num:~1!
)

pause


Report •

#6
December 8, 2010 at 19:17:35
yeah that's what i did :P but i don't know how to get the numbers like this

0000000
0000001
0000002

where there is a zero in front of everything :P


Report •

#7
December 8, 2010 at 19:52:14
That's exactly what #5 does....

Report •

#8
December 13, 2010 at 17:22:05
i understand it moves up ;) lols you neglected to realize that there is a zero in the bginning

0 000001
0 000002

^
|
see zeros

not

1 000001
1 000002


Report •

#9
December 13, 2010 at 20:22:04
Perhaps you should run the script ;).


   set num=%%a
   echo !num:~1!

!num:~1! removes the very first character (i.e the "1" at the front) leaving you with a seven digit number with leading zero's.


Report •

#10
December 14, 2010 at 17:07:13
oh bite me!!
of course i ran the script XP

@echo off & setlocal enabledelayedexpansion
set num=%%a

for /l %%a in (1000000 1 9999999) do echo %%a

but then you totally lost me in were i add the set "num=%%a" and "echo !num:~1!"


Report •

#11
December 15, 2010 at 07:33:27
Alright I'm only going to explain this once.

You want a number that is seven digits with leading zero's right?

@echo off & setlocal enabledelayedexpansion
for /l %%a in (10000000 1 19999999) do (
   set num=%%a
   echo !num:~1!
)

pause

set num=10000000
echo 0000000
set num=10000001
echo 0000001
set num=10000002
echo 0000002
......

What is 10000000 without the first digit????

Run it without changing it!, then you might see that it actually works.


If you choose not to believe it then figure it out yourself.


Report •

#12
December 15, 2010 at 07:40:24
Judago your right.

@echo off & setlocal enabledelayedexpansion
for /l %%a in (10000000 1 19999999) do (
set num=%%a
echo !num:~1!
)

pause


Just tried it worked fine just moves fast lol.


Report •

#13
December 16, 2010 at 05:58:55
thank you Judago :) it worked

Report •

#14
December 16, 2010 at 06:01:20
i'm creating a phone number book dictionary :P don't ask y it's just better than doing random digits

Report •

#15
December 16, 2010 at 09:34:35
No worries ;)

Report •

#16
December 16, 2010 at 21:20:19
yeah i know right but fast is good in my case!

because i'm taking that code and putting it into a bat file.

example.bat has the code


then in cmd

start example.bat > C:\phone_dictionary.dict


then there we go instant phone dictionary to use for educational purposes ;)


Report •

#17
December 17, 2010 at 04:09:17
@daniel.marriott, if your problem is that the script runs fast, I can give you a solution. I have an old 80286-based PC in the loft, which you are welcome to buy, and if you run it on that, I can guarantee it will not be fast. ;-)

Report •

Ask Question