FindFile

FindFile is a built-in scripting function that searches for all files that match a given search string.

Function Group Execution Windows Embedded Thin Client Mobile Access
FindFile File Synchronous Supported Not supported Supported (see “Notes”) Not supported

Syntax

Web Studio Help es2fr function file findfile.xml d122526e78 FindFile

  FindFile( strFile, optTagFilesFound, optNumTimeout )  
strFile
The name of the file(s) to search for.

You may use wildcards (*) to find multiple files. For example, *.gif to find all GIF files or log*.txt to find all log files in a sequence (e.g., log001.txt, log002.txt, log003.txt).

By default, the function only searches the project folder, but you may specify a file path (either relative or absolute) to search elsewhere. For example, if strFile is defined as…
  \volume name or IP addressLogslog*.txt  

…then the function will search the Logs directory on the specified network volume.

optTagFilesFound
An array (of String type) that will receive the names of the matching files. The array name must be enclosed in quotes; if it is not, then the function will try to get the contents of the array.

This is an optional parameter. If no value is specified, then the file names will not be saved and the function will only return the number of files found. For more information, see “Returned value” below.

The specified array will receive only the file names and not their paths, even if you define strFile to search outside the project folder. Also, the file names will be saved starting at array position 1 (e.g., MyArray[1]).

optNumTimeout
The timeout period (in milliseconds) for the function to be successfully executed.

This is an optional parameter. If no value is specified, then the project will continue searching until it has completely searched the specified directory.

Note: optNumTimeout is not supported if the target system / project server is a Windows Embedded device.

Returned value

This function will return one of the following values:
Value Description
-1 Function timed out.
0 No matching files found.
n Number of matching files found.

Notes

This function can be called from scripts executed on project clients (e.g., Graphics Script, Screen Scripts, Command animations), but the function itself is always executed on the project server. By default, it only searches the project folder on the server, and if strFile includes a relative file path, then it is relative to that folder.

Furthermore, because the function is executed synchronously on the project server, if strFile is poorly defined and/or optNumTimeout is not used, then the entire project — both the server and the clients — may hang while it searches for the files.

Finally, optNumTimeout is not supported if the target system / project server is a Windows Embedded device.

Examples

Find all text files in the Server’s project folder:
  FindFile( "*.txt" )  
Find all Microsoft Word files in the project folder and then send the names of the matching files to StringArray, within a timeout period of 1000 milliseconds:
  FindFile( "*.doc", "StringArray", 1000 )  

FindFile