FindAllFiles

InstallShield 2013 » InstallScript Language Reference

The FindAllFiles function searches an entire hierarchical subdirectory structure starting with the specified directory, and it returns the name of the first file with a particular file specification. If the specified directory is the root directory, InstallShield searches the entire disk. The function stops at the first matching file name it finds.

Note: If the argument passed to nOp is RESET, InstallShield starts searching at the directory specified in the parameter szDir and continues searching the subdirectory structure until it finds a file matching szFileName. If nOp equals CONTINUE, the search continues where it finished the last time the function was called. Call this function repeatedly to find all occurrences of files that match szFileName.

The first time you call this function to begin a new search, set nOp to RESET. You can continue to search for all other occurrences of the specified file by setting nOp to CONTINUE and placing the function call in a loop that ends when the FindAllFiles function fails.

Finding Files that Match a File Specification

To find all files matching a file specification:

1. Assign to szDir the name of the folder to search.
2. Assign to szFileName the file specification, such as IS5*.txt.
3. Call FindAllFiles with nOp set to RESET.
4. While the return code from FindAllFiles is 0, save the file name in svResult; then call FindAllFiles with nOp set to CONTINUE.
5. Call FindAllFiles with nOp set to CANCEL.

Caution: You cannot use the XCopyFile function within a FindAllFiles(..., RESET), and FindAllFiles(..., CONTINUE) loop. If you call XCopyFile inside a FindAllFiles loop, the file name returned by FindAllFiles(..., CONTINUE) may be incorrect.

Syntax

FindAllFiles ( szDir, szFileName, svResult, nOp );

Parameters

FindAllFiles Parameters

Parameter

Description

szDir

Specifies the name of the directory to search.

szFileName

Specifies the file specification to search for. Wild-card characters are allowed in this parameter.

svResult

Returns the fully qualified name of the first matching file if found. If FindAllFiles fails, svResult remains unchanged.

nOp

Indicates search options. Pass one of the following predefined constants in this parameter:

CONTINUE—Resumes the search at the location where the previous search stopped.
RESET—Starts the search at the beginning of the directory specified by szDir.
CANCEL—Frees all files and folders that were accessed by previous calls to FindAllFiles. Call FindAllFiles with this parameter to ensure the success of subsequent file and folder operations on files and folders that have been accessed by FindAllFiles.

Return Values

FindAllFiles Return Values

Return Value

Description

0

Indicates that the function retrieved and returned a file that matched the specification.

< 0

Indicates that the function was unable to find a file that matched the specifications.

See Also