Chapter Contents

Previous

Next
FINDFILE

FINDFILE



Searches a directory for a file

Language element: function
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 the SAS System 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. Context 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.

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 pathname, which can be up to 255 characters long. SAS character variables have a maximum length of 32767.


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.

See Also


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.