Hitachi

JP1 Version 11 JP1/Script Description and Reference (For Windows Systems)


7.1.4 For...End For

Purpose

Flow control statement that iterates a sequence of statements for all the files in a specified folder.

Syntax
For VarName = Filemask Do
  [Statements]
  [Exit For]
  [Statements]
End [For]
Arguments
VarName

Specify a variable name for storing the file names. Comply with the variable naming conventions. You cannot specify an array variable or an element of an array variable.

Filemask

Specify the file names you want to search by full path. A wildcard can be included. Enclose the full path with double quotation marks (").

Statements

Write the sequence of statements to be executed in the loop. Write the statements between For and End For. These statements are executed repeatedly until no more files can be found in the path specified in the For...End For.

You can write multiple statements in Statements, with a line feed after each one.

Description

The For...End For statement iterates a sequence of statements for all the files in a specified folder. When no more files can be found in the specified path, control moves to the statement following the End For statement.

The Exit For statement can only be used within a For...End For or For...Next control structure as a means of immediately exiting a For...End For loop. You can write any number of Exit For statements anywhere in the For...End For loop.

You can nest For...End For statements by placing one For...End For within another. When nesting For...End For loops, specify a different variable name in each VarName.

When *.* is specified in Filemask, file names other than . and .. are stored in VarName.

Supplementary note
  • When the system searches for the files in a For...End For loop, it also retrieves any short file names converted into MS-DOS file format and saved for compatibility.

  • For the For...End For loop, the file search order is not guaranteed.

Example
' Back up the script files in the execution folder to
' another folder.
Dim path1 ,bkupDir
bkupDir = _BIN_+"BKUP\"
MakeDir(bkupDir)
 
' Search for script files.
For path1 = _BIN_+"*.SPT" Do
  ' Ignore folder.
  If IsExistDir(_BIN_+path1) = False Then
    ' Back up to another folder.
    Copy(_BIN_+path1 ,bkupDir+path1)
  End If
End For
JP1/Script version

Supported from JP1/Script 01-00.