GETNEXTFILE         Get file or folder names on local PC

Top  Previous  Next

Syntax:

GETNEXTFILE

[ file name ] [ /options ]

Arguments:

[ file name ]

Variable or string defining a file or path name to look for; wildcard characters allowed; if no path is defined Robo-FTPs working folder is used.

Options:

/incldirs

Return local folder name(s) as they are found. (Formerly this was the /subdirs option.)

 

/newest

Get the newest file in the folder.

 

/next

Get the next file or folder name in a local folder; omit this option to obtain the first file from a given local folder; if you wish to obtain subsequent files from this same folder, use this option until you find the desired file or no more files are found (see Important below).

 

/oldest

Get the oldest file in the folder.

 

/timeout=nn

Time-out in seconds to wait for presence of the file; if this option is omitted, Robo-FTP looks for the file and if nothing is found, $ERROR_NO_FILE_FOUND is returned; otherwise $ERROR_WAIT_TIMED_OUT is returned.

 

 

This script command checks for (and optionally waits for) the existence of a file defined by the [ file name ] argument. If a matching file is detected, its file name is saved in the %nextfile variable and its full path name is saved in the %nextpath variable. The date and time of the file are also saved in the %nextfiledate, %nextfiledatetime, and %nextfiletime variables. The size of the file (excluding a folder), in bytes, is saved in the %nextfilesize variable.

 

The use of this command creates what is referred to as the hot send function whereby Robo-FTP automatically sends files when they are placed in a known location.

 

If a file is open by another application, it will not be ‘seen’ by this command. Furthermore, the same file will be returned on subsequent iterations of this command unless it is deleted or renamed.

 

The /next option allows the entire contents, both files and folder names, of local folders to be traversed and saved in variables for use in script processing. Without this option, the first file found in the specified folder will always be returned.  Use of this option with the /timeout option is not supported.

 

 

Important

For most reliable operation, use the /next option only on static local folders (i.e., where no new files are being added and none are being deleted) since each successive /next skips one file as Robo-FTP scans through a given folder. When /next is omitted, this command always returns the first file that appears in the folder (files are returned in unsorted folder order).

 

Consider the following example where Robo-FTP waits indefinitely for any file with a .txt extension to be created in its working folder.

GETNEXTFILE "*.txt" /timeout=0

 

Once such a file exists, its name is saved in the %nextfile variable, its path and name is saved in the %nextpath variable, and script execution resumes.

 

Consider the following example where all the files in the specified folder are sent to an FTP site.

 

:label

GETNEXTFILE "\upload_dir\*.*" /timeout=2

IFERROR= $ERROR_WAIT_TIMED_OUT goto sent_last_file

SENDFILE %nextfile /type=BIN

IFERROR goto xmt_error

DELETE %nextfile

GOTO label

:sent_last_file

 

Consider the following example in which the file and folder names in the current local folder are identified and displayed by using the /next option.

 

GETNEXTFILE "*.*" /incldirs

:loop

IFSTRCMP %nextfile "" goto dir

!DISPLAY %nextfile

!DISPLAY %nextfolder

!DISPLAY %nextpath

PAUSE /for=1

GOTO next

:dir

IFSTRCMP %nextfolder "" goto error

!DISPLAY %nextfile

!DISPLAY %nextfolder

!DISPLAY %nextpath

PAUSE /for=1

:next

GETNEXTFILE "*.*" /next /incldirs

IFERROR= $ERROR_NO_FILE_FOUND goto finish        

GOTO loop

:error

MESSAGEBOX "This shouldn't ever appear..."

STOP

:finish

MESSAGEBOX "Shown all files!"

 

The /newest and /oldest options are normally used with a wildcard [ file name ] to obtain the name of the newest or oldest file present. Use of these options with the /next option is not supported. Consider the following example where all files are sent to an FTP site beginning with the newest.

 

:next_file

GETNEXTFILE "*.*" /newest

IFERROR= $ERROR_NO_FILE_FOUND goto label

SENDFILE %nextfile

DELETE %nextfile

GOTO next_file

:label

 

The /incldirs option may be used if you wish local folder names to be returned along with regular file names as they are found. When a folder is found, it is saved in the %nextfolder variable and the %nextfile variable is set to an empty string. The /oldest and /newest options have no affect on the folder names returned by the GETNEXTFILE command. Consider the following example that shows how folder files are distinguished from other files.

 

:look_for_folder

GETNEXTFILE "*.*" /incldirs /next

IFERROR= $ERROR_NO_FILE_FOUND goto error

IFNSTRCMP %nextfile "" goto look_for_folder

; both %nextfile and %nextfolder will not be empty at same time

DISPLAY %nextfolder

GOTO look_for_folder

:error

 

The date and time of the file obtained with the command is saved to three internal variables named %nextfiledate, %nextfiledatetime,  and %nextfiletime. This permits you to directly compare the file’s date and time to values of your choosing. Consider the following example that shows how a file newer than a specified date may be found.

 

:not_new

GETNEXTFILE "*.*" /next

IFERRORIFERROR= $ERROR_NO_FILE_FOUND goto error

SET filedate = "file date is " & %nextfiledate

DISPLAY filedate

IFDATE< "06-30-02" goto not_new

MESSAGEBOX "found file created after June 30, 2002"

STOP

:error

 

Related Commands: WORKINGDIR, GETSITEFILE

See also:Using the %nextfile, %nextpath, and %nextfolder Variables,

Using the %nextfiledate, %nextfiledatetime, %nextfilesize, and %nextfiletime Variables, The Hot Send Feature