Previous Page | Next Page

Functions and CALL Routines under OpenVMS

FINDFILE Function: OpenVMS



Searches a directory for a file.
Category: General-Purpose OpenVMS
OpenVMS specifics: All aspects are host-specific

Syntax
Details
Example
See Also

Syntax

FINDFILE(file-specification,context)

file-specification

specifies the file specification of the file that you are searching for. It can contain any valid OpenVMS file specification, including wildcards. The value for file-specification can be a character variable, a character literal enclosed in double quotation marks, or another character expression. You must have access to the file that you are searching for.

context

is a variable used internally by SAS to maintain the search context between executions of FINDFILE. It must be initialized to 0 before the first execution of FINDFILE for a given file-specification and must not be modified between executions. The context value must be a numeric variable initialized to 0; it cannot be a literal 0. You can use FINDFILE for multiple search streams by specifying a different context variable for each stream. For example, you can have variables named CONTEXT1 and CONTEXT2.


Details

The FINDFILE function searches all directories and subdirectories for file-specification and returns the first filename that matches the file specification given. Subsequent calls return other filenames that match the specification. For more information, see the description of the CALL FINDEND routine in CALL FINDEND Routine: OpenVMS.

The return value is the name of the file that matches file-specification. If no file matches or if the last one in the list has already been returned, a blank is returned. The target variable must be long enough to contain an OpenVMS file specification, which can be up to 4095 characters long (for ODS-5 enabled volumes). SAS character variables have a maximum length of 32,767.


Example

The following example uses the FINDFILE function:

context=0;
fn=findfile('myprog*.sas',context);
do while (fn ^= ' ');
   put fn;
   fn=findfile('myprog*.sas',context);
end;

This example searches the user's directories for a filename that matches MYPROG*.SAS; for example, if it finds a file named MYPROG12.SAS, then FN is set to myprog12.sas .

Note:   If you use a file specification that is greater than 200 characters (such as a filename allowed by ODS-5), then you must specify a LENGTH statement for the variable to receive the filename. The following code shows the LENGTH statement for the previous example:

length fn $ 4096;

  [cautionend]


See Also

Previous Page | Next Page | Top of Page