Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

batch file help

Status
Not open for further replies.

okysPPanda

Technical User
Feb 23, 2004
3
US
What I am trying to do is create a sript that will take an input value in the form of a number, and then copy "1.exe" with the input number as the name. Then I want it to subtract one from the input number and repeat the process, creating many #.exe files, all identical except for the name. Finally, I want to be able to stop the process when the file 0.exe is created.
I need this file to work for Windows 2000, but would like it to work with other versions of Windows too.
The following is what I have come up with so far. I am getting an error when it reaches "if /i %abc% LSS %1 goto END" the process stops and says 0 was unexpected at this time.


set [[/a [%1 GTR 999]] [/p [abc=%1]] goto ER2]
set [[/a [%1 LSS 1]] [/p [abc=%1]] goto ER2]
:N2
copy 1.exe c:\winnt\%abc%.exe
set /a %abc% "-=" 1
set [[/a [%1 GTR 1]] [/p [%abc%-=1]] goto N2]
if /i %abc% LSS %1 goto END
goto N2
:ER2
echo You must specify a number >0 and <1000, as in "1" or "999"
:END

If anyone could show me what I am doing wrong, or possibly show me an easier way to do this, it would be much appreciated.
 
As far as I'm aware, DOS's batch file processes are not made to be used in the maner you are describing.

The use of memory variable manipulation for increasing/decreasing a numerical sequence (such as adding/subtracting) are indicitative of a programming language (such as Asm, BASIC, C, and so forth).

In Short: You're better off using a programming language.

Besides:

[ol][li]Where's the "User's Input"? or is it receiving the starting "number" from the commandline in [highlight]%1[/highlight]?[/li]

[li]Has your code worked? if so, does it stop at a certain number?[/li]

[li]Also, what's up with the minus sign in front of the equal signs?[/li]
[/ol]


--MiggyD
 
There is nimber of scripting languages, enhancing DOS that way. One I've heard of is REX. Or one could try to use some UNIX-originated sghell language.
I do not know if it could be done in pure DOS (or Win2000 for that matter).
 
in response to MiggyD:
1. the user input is in the form of the %1 variable.
2. No, my code has not worked, because I cant seem to get the syntax right. I believe that Dos is able to do simple arithmatic. What I need it to do is incredibly basic. all I want to be able to do is add 1 to a variable. On the Microsoft site, I think it is saying that arihmatic functions can be used in the set command.
 
WOW! I was really overcomplicating things. I fixed the problem. Below is the script that works-

set /a abc=%1
:N1
copy 1.exe c:\winnt\%abc%.exe
set /a abc=%abc% - 1
if %abc% LSS 1 goto end
goto N1
:end
echo works!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top