Variables and Loops

Reference:        Programming a Script

                        Script Language

                        Alphabetical Command List 

                        Topical Command List 

Variables and while loops became available with the 3.0 release of Beyond FTP.  Variables provide two great advantages: An efficient way to enter information that is required across a number of commands, such as a path name or a server name;  and an easy way to control the operation of a script without resorting to file copies and presence checks to simulate decisions.  The templates are full of examples of capturing information into a variable that is then used for many other operations.

Variables are specified like wildcards by using the percent ”%” sign followed by the variable name in single quotes.  This allows you to place variables into literal strings without the inconvenience of string operators to construct the final result.  This is especially helpful in constructing file names with variables and wildcards. 

While loops provide controllable repetition.  The While Next form allows you to generate a list of files and to process each item in the list individually.  The great advantage of this command is that decisions can be made for each individual file in a list.  There is no danger of having the included files change over the course of the script.  For example, if you were to copy a list of files using the asterisk wildcard (e.g. *.txt) and then delete the source files using the same wildcard, it is possible to delete a file that arrived since the original copy list was created.  The While Next command eliminates this possibility, since the list is created once and then all commands are processed using the results of that list.  The disadvantage of the While Next command is that files are processed in order.  There is no parallel operation.  This can be overcome by doing the longer operations, such as transfers, outside of the While loop and then processing through the list of copied files to determine which source files to process or delete.