GETNEXTFILE Get file or folder names on local PC |
Top Previous Next |
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 and %nextfolder variables. 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 FileLink 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.
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 FileLink 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 FileLink 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 the remote system.
: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..." :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 the remote system 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 IFERROR= $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 See also: Using The %nextfile, %nextpath, and %nextfolder Variables, Using The %nextfiledate, %nextfiledatetime, %nextfilesize, and %nextfiletime Variables,
|