Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
79 user(s) are online (65 user(s) are browsing Forums)

Members: 0
Guests: 79

more...

Headlines






Looping in DOS batch scripts
Home away from home
Joined:
2006/11/26 21:45
From a dying planet
Posts: 4331
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

_________________
People are dying.
Entire ecosystems are collapsing.
We are in the beginning of a mass extinction.
And all you can talk about is money and fairytales of eternal economic growth.
How dare you!
– Greta Thunberg
   Report Go to top

Re: Looping in DOS batch scripts
Home away from home
Joined:
2006/11/20 16:26
From Norway
Posts: 2988
@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.
   Report Go to top

Re: Looping in DOS batch scripts
Home away from home
Joined:
2006/11/26 21:45
From a dying planet
Posts: 4331
@LiveForIt

This is AmigaDOS

_________________
People are dying.
Entire ecosystems are collapsing.
We are in the beginning of a mass extinction.
And all you can talk about is money and fairytales of eternal economic growth.
How dare you!
– Greta Thunberg
   Report Go to top

Re: Looping in DOS batch scripts
Home away from home
Joined:
2006/11/20 16:26
From Norway
Posts: 2988
@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.
   Report Go to top

Re: Looping in DOS batch scripts
Home away from home
Joined:
2006/11/26 21:45
From a dying planet
Posts: 4331
@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...

_________________
People are dying.
Entire ecosystems are collapsing.
We are in the beginning of a mass extinction.
And all you can talk about is money and fairytales of eternal economic growth.
How dare you!
– Greta Thunberg
   Report Go to top

Re: Looping in DOS batch scripts
Just popping in
Joined:
2017/5/18 11:12
From Audruicq, France
Posts: 93
Hi,

ForEach command would fit what you want to do maybe?

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

   Report Go to top

Re: Looping in DOS batch scripts
Home away from home
Joined:
2006/11/26 21:45
From a dying planet
Posts: 4331
@Petrol

Good call, exactly what i was looking for

Thanks a lot

_________________
People are dying.
Entire ecosystems are collapsing.
We are in the beginning of a mass extinction.
And all you can talk about is money and fairytales of eternal economic growth.
How dare you!
– Greta Thunberg
   Report Go to top

Re: Looping in DOS batch scripts
Just can't stay away
Joined:
2006/12/1 18:01
From Copenhagen, Denmark
Posts: 1276
@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



   Report Go to top

Re: Looping in DOS batch scripts
Home away from home
Joined:
2006/11/26 21:45
From a dying planet
Posts: 4331
@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

_________________
People are dying.
Entire ecosystems are collapsing.
We are in the beginning of a mass extinction.
And all you can talk about is money and fairytales of eternal economic growth.
How dare you!
– Greta Thunberg
   Report Go to top

Re: Looping in DOS batch scripts
Just popping in
Joined:
2019/11/27 12:32
From RNO
Posts: 25
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!

   Report Go to top

Re: Looping in DOS batch scripts
Home away from home
Joined:
2006/11/26 21:45
From a dying planet
Posts: 4331
@jPV

Thank you, worth a peek

_________________
People are dying.
Entire ecosystems are collapsing.
We are in the beginning of a mass extinction.
And all you can talk about is money and fairytales of eternal economic growth.
How dare you!
– Greta Thunberg
   Report Go to top





[Advanced Search]



Powered by XOOPS 2.0 © 2001-2016 The XOOPS Project