Continuing from last time.
The usage for the basic for loop looks like:
FOR %variable IN (set) DO command [command-parameters] %variable Specifies a single letter replaceable parameter. (set) Specifies a set of one or more files. Wildcards may be used. command Specifies the command to carry out for each file. command-parameters Specifies parameters or switches for the specified command.
For example, to copy every file in the current directory into its own subdirectory named after the file under the \Test directory, you could run this on the command line:
for %F in (*) do xcopy "%F" "\Test\%F\"
This would copy the file foo.txt to \Test\foo.txt\foo.txt and bar.bmp to \Test\bar.bmp\bar.bmp. Note the quotes in the xcopy command; these are there in order to make sure that it does the right thing if a file happens to contain spaces in its name.
The next part of the help message is:
To use the FOR command in a batch program, specify %%variable instead of %variable. Variable names are case sensitive, so %i is different from %I.
This can be troublesome when writing about a for loop [as in email or in a blog]. You have to assume that the reader knows about it, or you have to explain it every time you write a for loop. Even if you type a for loop in someone's Command Prompt, you probably have to explain that if they want to put the line in a batch file, they'll have to replace, e.g. %F with %%F throughout the for loop. For instance, the above for loop would look like this in a .bat or .cmd file:
for %%F in (*) do xcopy "%%F" "\Test\%%F\"
For this reason, I will use a single % in for loops on this site because it's easier to type [and possibly easier to read] and assume that the reader understands this point.