Using the %counter variable
<< Click to Display Table of Contents >> Navigation: Robo-FTP User's Guide > Script Programming > Internal Script Variables > Using the %counter variable |
The %counter variable provides a simple counter mechanism. The %counter variable initially evaluates to 1. Every time the %counter variable is evaluated, it is incremented by 1.
After reaching the value 65535, this variable rolls back to 1. You can also subscript to get independent, zero-padded counters of a specific length. For example:
%counter[2] - this counts from "01" up to "99" and then finally rolls over to "01"
%counter[3] - this counts from "001" up to "999" and then finally rolls over to "001"
Each such counter is independent of each other.
Each counter can be individually reset to the initial value using SET %counter[N]. For example:
SET %counter[2]
Consider the following example in which a number of downloaded files are renamed locally using %counter:
FTPLOGON "mysite"
:morefiles
GETSITEFILE "*" /oldest
RCVFILE %sitefile
IFERROR GOTO end
SET newfilename = %counter[2] + "." + %sitefile
MOVE %sitefile newfilename
GOTO morefiles
:end