Excuse my newbie question but I haven't had to touch bat scripts since the days of the autoexec.bat... and that one was even called from the system directly.
So I wonder how I can pass in arguments to my bat script?
For example I want to create n directories with a certain name. I would like to use a construct such as this one:
for %%N in (1 to $arg1$) do mkdir $arg2$-%%N
As a result I would like to have N directories called
- name-1
- name-2
- name-3
... and so on.
Thanks!
Batch files use positional parameter numbers (%1, %2, %3) to indicate arguments. For your example, it would be:
for %%N in (1 to %1) do mkdir %2-%%n
Here is a reference guide.
But the construct of your for loop is incorrect too - there is no "to" keyword in batch files as far as I know. The thing in parentheses is supposed to be a set (such as: 1 2 3 4) - I'm not sure you can loop like you want to do without using labels and goto...
Here is the syntax for the FOR command.
Here is how you would do the loop using labels and goto - its not pretty from a programmer's point of view - but what about a batch file is?
it is just %1 %2 ... %n for argument1, argument2, ..., argumentn
see this for example.
The for loop I did like this:
I think what you want is :