I am trying to create a batch script which would perform the same action for each parameter given. For example, giving X files as parameters:script.bat "file1.txt" "file2.txt" "file3.txt" "file4.txt" ... "fileX.txt"
will rename them to:"file1.bin" "file2.bin" "file3.bin" "file4.bin" ... "fileX.bin"
Rename is just an example, I will need it for more complex operations too.
I guess it should be something like for each
but I'm new in batch scripts.
I just wonder if I could just increment %1
index...
You can use SHIFT
to shift the parameters left. In other words calling shift will put the second parameter to %1, the third to %2 etc.
So you need something like:
@ECHO OFF
:Loop
IF "%1"=="" GOTO Continue
ECHO %1
SHIFT
GOTO Loop
:Continue
This will just print the arguments in order, but you can do whatever you want inside the loop.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With