GETFILEARRAY         Get list of matching local file(s)

<< Click to Display Table of Contents >>

Navigation:  Robo-FTP User's Guide > Script Programming > Script Commands > All Script Commands >

GETFILEARRAY         Get list of matching local file(s)

Syntax:

GETFILEARRAY

filename  varname [ /options ]

Arguments:

filename

Variable or string defining a file or path name to look for; wildcard characters allowed; if no path is defined

 

varname

the array name to populate.

Options:

/subdirs

Search sub-folders for files matching the [ file name ] argument.

 

/excludedirs=xx

Exclude all files in directories that match the name of the provided argument no matter where it appears in the path. To specify multiple directories, you can separate them with the pipe character (|) or use multiple /excludedirs options.

 

/maxfiles=nn

Limits the number of files returned to the specified value. If the /subdirs option is used, this specifies the maximum number of files returned per directory.

 

If you need to download a file please see the Help page for the RCVFILE script command.

Note

Robo-FTP offers numerous commands for monitoring for files and iterating over directory structures on local and remote servers. 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. Please see the chapter Monitoring for Files and Iterating over Directory Structures for a description of these commands and recommendations for which commands to use in a particular situation.

 

This script command searches the current local directory for the file specified in the [ file name ] argument. If any matching files are found, the full path to that file is added to the array varname[*].

 

GETFILEARRAY ignores files that are exclusively locked by other applications or that are inaccessible due to security permissions. This command also ignores all files with the "hidden" or "system" file system attribute. You can use the DOS attrib.exe program to change these attributes. GETFILEARRAY will not ignore a hidden file if you specify that file's name explicitly.

 

;; In this example, myfile.txt has the "hidden" file system attribute set

GETFILEARRAY "*.txt" var ;; This will ignore "myfile.txt"

GETFILEARRAY "myfile.txt" var ;; This will find myfile.txt

 

Use the WORKINGDIR command to change the current directory before calling GETFILEARRAY if the file you want to find in not in the current directory or, alternatively, the /subdirs option may be used to find files in any subdirectory of the current directory.

 

This command is especially efficient with directories containing very large numbers of files. Each call to GETNEXTFILE or GETFILE with wildcards must iterate over previously checked file on each call, so for very large directories or directory trees it is much faster to use GETFILEARRAY and GETNEXTFILE (without wildcards) together as in the following example:

 

GETFILEARRAY "*" var

SETNUM counter = 0

SETNUM size = var[*]

IFNUM= size 0 GOTO loop_done ;; skip loop if array is empty

:top_of_loop

GETNEXTFILE var[counter]

IFERROR GOTO next

!DISPLAY %nextfile

!DISPLAY %nextpath

!DISPLAY %nextfiledatetime

!DISPLAY %nextfilesize

PAUSE /for=1

GOTO next

 

:next  

SETNUM counter = counter + 1

IFNUM< counter size GOTO top_of_loop

:loop_done

 

As an alternative, the DIFF and GETDIFF commands can be used together instead (when invoked without a pre-existing snapshot database) for the same purpose and with similar performance improvements over a simple loop using GETNEXTFILE with wildcards.

 

Related command(s): GETREWIND, GETNEXTFILE, FTPGETFILE, FTPGETREWIND, GETSITEFILE, FILECOMPARETO, FILECOMPAREFROM

See also: Using the %nextfile, %nextpath, and %nextfolder Variables, Using the %nextfiledate, %nextfiledatetime, %nextfilesize, and %nextfiletime Variables, Using Wildcards, Using Arrays