Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
100 user(s) are online (92 user(s) are browsing Forums)

Members: 3
Guests: 97

trixie, LiveForIt, VooDoo, more...

Support us!

Headlines

 
  Register To Post  

Looping in DOS batch scripts
Home away from home
Home away from home


See User information
Hey,

a question to all the DOS batch experts.

I'd like to create a looping batch script that does slightly different things (but effectively the same), but to different targets.
I know how to do it in rexx, but i'm not firm enough to pull it off in .bat.

Here's what i like to achieve (i have the loop figured out, but i don't know how to set up the target(s), so that the loop will read them one by one.

target="path1""path2""path3""end"

LAB Main
if target EQ "end"
    
QUIT
endif
if 
target EQ "path1"
    
do stuff
endif
else
    do 
other stuff
endif
SKIP BACK Main

Any help appreciated, thank you very much

Go to top
Re: Looping in DOS batch scripts
Home away from home
Home away from home


See User information
@Raziel

MSDOS .bat files complete different, You might consider writing a py or ruby or vbs script, they are easier to write.

(NutsAboutAmiga)

Basilisk II for AmigaOS4
AmigaInputAnywhere
Excalibur
and other tools and apps.
Go to top
Re: Looping in DOS batch scripts
Home away from home
Home away from home


See User information
@LiveForIt

This is AmigaDOS

Go to top
Re: Looping in DOS batch scripts
Home away from home
Home away from home


See User information
@Raziel

AmigaDOS don’t use #?.bat as extension, only protection bit S for script.

Anyway, if you have directory with sub directories.
You can use LIST command with LFORMAT, to generate a new script. for etch directory.

Anyway this can be easier in AREXX, way better for strings.

(NutsAboutAmiga)

Basilisk II for AmigaOS4
AmigaInputAnywhere
Excalibur
and other tools and apps.
Go to top
Re: Looping in DOS batch scripts
Home away from home
Home away from home


See User information
@LiveForIt

Actually i've got it all figured out, the only thing missing is a way to give a variable with differing entries to the loop.

I know there is .KEY, but is there something like .KEY.1(.2,.3 etc.)
That way i could simply enhance a counter (e.g. i=i+1) during the loop and simply ask for .KEY.i.

...

I know arexx is far better suited for this (that's why most of the work is done by an arexx script already).
The problem is, that i need to be IN the directory when starting the arexx script, because arexx will only act on the directory it is started in, so i have to copy the rexx script to either directory and that is what i'd like to do in a batch loop.

Right now i mirrored four commands in the batch one after the other, each altering only in the path where the rexx script is copied to and started in.

There has to be a smarter way...

Go to top
Re: Looping in DOS batch scripts
Just popping in
Just popping in


See User information
Hi,

ForEach command would fit what you want to do maybe?

https://wiki.amigaos.net/wiki/AmigaOS_ ... Command_Reference#FOREACH

Go to top
Re: Looping in DOS batch scripts
Home away from home
Home away from home


See User information
@Petrol

Good call, exactly what i was looking for

Thanks a lot

Go to top
Re: Looping in DOS batch scripts
Just can't stay away
Just can't stay away


See User information
@Raziel

Quote:
The problem is, that i need to be IN the directory when starting the arexx script, because arexx will only act on the directory it is started in
This sounds to me like a misunderstanding - although I am not quite sure what you're actually trying to do, once you know where to do it.

You can always build a path in a string variable, even an absolute one, or a relative one starting with one or more '/' for that matter, and use that string variable to "address command 'cd ' || pathvar" or something, i.e. effectively set the current dir of your running script's process somewhere else.

Normally it's good practice to save your current dir first, so you can restore it at the end of the script.

Best regards,

Niels



Go to top
Re: Looping in DOS batch scripts
Home away from home
Home away from home


See User information
@nbache

I need to make a note of this, might actually save me the batch script...then again, it's down to some lines with foreach

But thank you for the suggestion, Niels

Go to top
Re: Looping in DOS batch scripts
Just popping in
Just popping in


See User information
I once made a file size based counter ;) I don't know if there would be other way, but if you don't have the ForEach command (on OS3, for example), then you could hack it like this (modified it to do what you asked) :P

some paths you want to handle
setenv 1 
"RAM:"
setenv 2 "T:"
setenv 3 "SYS:"

init our counter to zero
echo "" noline ENV:counter

loop start
lab loop

increase counter by one
echo "" >> ENV:counter

read the counter value to a local variable
set i 
`list env:counter lformat "%L"`

; if 
we have a corresponding filethen do stuff and loop
if exists env:$i
   
Get contents
   set p 
`getenv $i`
   ; Do 
stuff
   
echo "Processing $p"
   
if $p eq "SYS:"
      
echo " Special case!"
   
else
      echo 
" Normal case..."
   
endif
   ; 
clear variables
   unsetenv $i
   
unset p
   
jump back in the script
   skip loop back
endif

otherwise clean up and quit
unsetenv counter
unset i


And that would output:
Processing RAM:
 
Normal case...
Processing T:
 
Normal case...
Processing SYS:
 
Special case!

Go to top
Re: Looping in DOS batch scripts
Home away from home
Home away from home


See User information
@jPV

Thank you, worth a peek

Go to top

  Register To Post

 




Currently Active Users Viewing This Thread: 1 ( 0 members and 1 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2024 The XOOPS Project