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
FindFile File Synchronous Supported Supported Supported

Syntax

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 address\Logs\log*.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.

Note: The array will receive only the file names and not their paths, even if you define strFile to search outside the default directory.
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.

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 may be called by any project client, but it is always executed on the project server. By default, it only searches the server's project folder, and if strFile includes a relative file path, then it must be relative to the that same directory.

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 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 )