Monitoring for Files and Iterating over Directory Structures

<< Click to Display Table of Contents >>

Navigation:  Robo-FTP User's Guide > Script Programming > Select Topics in Script Programming >

Monitoring for Files and Iterating over Directory Structures

 

A common requirement for automating processes is to have the ability to monitor for the existence of a file or files on the local or remote server, including iterating over a list of files in a directory or directory structure.

 

Robo-FTP offers numerous commands for implementing these types of tasks. There is significant overlap in capabilities between these commands, but there are also important differences that often make one command better suited to a particular task than the others.

 

This chapter provides a brief summary of the available commands and some examples that may help you determine which approach best fits your requirements.

 

In general, for every command used to monitor for files on a local server there is an equivalent command for monitoring for files on a remote server. These commands are described below in pairs as the behavior is largely the same between the "local" and "remote" versions of these commands.

 

GETFILE / FTPGETFILE

 

These commands are most commonly used for the following types of requirements:

Watch a certain directory and wait for a file to appear

Check a directory to see if a certain file already exists

Determine the name of a file in a particular directory that changes daily

Iterate over a list of files in a directory structure and perform tasks (such as upload/download) on each file

 

GETNEXTFILE / GETSITEFILE

 

These commands are nearly identical to GETFILE / FTPGETFILE, so in most cases we recommend using GETFILE / FTPGETFILE. However, GETNEXTFILE / GETSITEFILE have one important difference that may make them more appropriate for your specific task.

 

With the /incldirs option, GETFILE / FTPGETFILE are able to descend into subdirectories and return all files found in a directory structure. They will not return directories, just the files in those directories. The same option used with GETNEXTFILE / GETSITEFILE gives you finer control by actually returning each item in the directory structure and providing information about each item (including telling you whether the item is a file or a folder). This could be useful in a case where you want to know the names of folders within a particular folder and have your script make decisions based on the folders it finds.

 

DIFF / FTPDIFF

 

DIFF / FTPDIFF are used to keep track of differences in a directory structure between runs of your script. A good example of the kind of problem you can solve with these commands is a case where you want to run a script daily that downloads only the files in a directory or directory structure that are new or have changed since you last ran the script.

 

GETFILEARRAY

 

GETFILEARRAY is used to get a list of all matching local files. The advantage to doing it this way is that GETNEXTFILE or GETFILE can be very slow for very large directories as it is has to iterate over the files it has already found each time you call it.

 

Related command(s): DIFF, GETDIFF, FTPDIFF, FTPGETDIFF, GETFILE, FTPGETFILE, GETNEXTFILE, GETFILEARRAY, GETSITEFILE

See also: %difffileid, %difffilename, %difffilepath, and %difffiletext, %ftpdifffileid, %ftpdifffilename, %ftpdifffilepath, and %ftpdifffiletext, Using the %nextfile, %nextfolder, and %nextpath Variables, Using the %sitefile and %sitedir Variables, Processing Dynamic Folders, Using the built-in database engine