FOR Command

The FOR loop is the most powerfull tool provided by batch language to process various types of data, from integers, text files, command outputs and even directories. Thus, the FOR loop is an important piece to eleborate advanced and complex batch scripts and commands.

The FOR loops may seem difficult to understand and mysty for beginners, however, it is a very powerfull tool for batch programmers.

Synopsis - First Syntax

The first syntax, allows processing strings.

FOR %%A IN (string) DO (
:: some commands
)

Split string in tokens and processes specified commands for each token.

Note that you can discard any of the previous delimiters (experts line feeds or new lines) just by enclosing the token between single or double quotes. Note also that the double or single quote will remain in the tokens processed.

Synopsis - Second syntax

The second syntax is based on the use of the /f switch. It can process either strings, command or files. Note that strings are not processed the same way as the previous syntax.

FOR /F [options] %%A IN (object) DO (
:: some commands
)

Processes either a string, a command output or a file. For convienience, and to ease reading of the page, none of the previously describded parameters will describded again.


Dos9 manual pages, The Dos9 Project - Copyright © 2010-2014 Darkbatcher

This is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Please report bugs and mistakes at : <darkbatcher at dos9 dot org>