Please enable JavaScript to view this site.

Take Command / TCC Help v. 29

Purpose:Perform one of several alternate sets of commands based on the values of conditional expressions


Format:IFF condition1 THEN


[ELSEIFF condition2  THEN

commandset2 ]



commandset3 ]




Conditional expressions


One or more commands to execute if condition1 is TRUE


One or more commands to execute if condition1 is FALSE, but condition2 is TRUE.


One or more commands to execute if both condition1 and condition2 are FALSE.


See also: IF and @IF.




IFF is similar to IF, but it can perform one commandset when a conditional expression is true and a different commandset when it is false. Repeated use of the optional ELSEIFF clause permits IFF to sequentially evaluate multiple, independent conditional expressions, and execute the commandset associated with the first TRUE conditional expression, or, if none are true, the commandset associated with the optional ELSE clause. After execution of any one of the commandsets the command after the ENDIFF clause will be executed.


You must start a new line or include a command separator :


after each THEN

before each ELSEIFF

both before and after the ELSE.


The individual commands in each commandset may be separate lines of a batch file, or they may be separated by command separators, in any combination. A commandset may also be empty, The individual commands in a commandset may include any internal command, alias, external command, or batch file.


IFF statements can be nested, i.e., a commandset may include another IFF / ENDIFF group. You must make sure that each individual command / commandset is syntactically correct. If an "inner" IFF / ENDIFF group is in error, it may not be detected until after the "outer" ENDIFF has been executed.


If the last argument on the line is a single (, it is interpreted as the beginning of a command group. IFF will append the following lines (in a batch file) or prompt you for more input (at the command line) until it gets a closing ).




Be sure to read the cautionary notes about GOTO and IFF under the GOTO command before using a GOTO inside an IFF statement.


If you pipe data to an IFF, the data will be passed to the command(s) following the IFF, not to IFF itself.




The alias in this example checks to see if the parameter is a subdirectory. If so, the alias deletes the subdirectory's files and removes it (enter this on one line):


alias prune `iff isdir %1 then & del /s /x /z %1 & else & echo %1 is not a directory! & endiff`