|
Answer» Hello,
I am trying to write a batch file that TAKES a list of DIRECTORIES as input, compresses each directory using commandline WINZIP and renames the zip files in sequential order.
Problem is, I'm stuck trying to figure out how to even touch the arguments passed to the batch file.
From my research it looks like arguments are TYPICALLY accessed using the %1 - %9 variables, but what if there are more than 9 arguments? Referencing arguments in this manner does not seem scalable, and I still don't know how to iterate from %1 to %2.
How can I write a For loop that effectively says, for each argument that was passed, do (the process), increase the COUNTER by 1 and repeat?
ThanksSomething like this may work. Note you can have more than 9 arguments as each is processed as %1 by using the shift command:
Code: [Select]@echo off set count=0 :start if .%1==. goto next set /a count=%count%+1 . put your wzzip logic here always processing the %1 variable and using %count% as your sequential number . shift goto start :next
Hope this helps. Works great! Thanks for your help.
One other question though-- I have the batch file in C:\Temp. When I drag a few directories onto the batch file, I'd like it to put the output archive files in the same directory as the batch file. Instead the archives are always created in the default DOS directory. What's the best way around this?You can use %~dp0 notation for the wzzip output drive and path. This will result in the drive and path of the batch file itself.
FYI: the resulting drive and path includes a trailing backslash.
Good luck.
|