To check for the existence of a file, use the QUERY method of the Stream class. The following ISTHERE.CMD program accepts a file name as a command line argument and checks for the existence of that file.
/* ISTHERE.CMD -- test for the existence of a file */ parse arg fid /* Get the file name */ qfile=.stream~new(fid) /* Create stream object */ if qfile~query('exists')='' then /* Check for existence */ say fid 'does not exist.' else say fid 'exists.'
In the example, a stream object is created for the file even though it may not exist. This is perfectly acceptable. Remember that the file is not opened when the stream object is created.
The QUERY method accepts one argument. To check for existence, specify the string 'exists' as shown above. If the file exists, QUERY returns the full-path specification of the stream object. Otherwise, QUERY returns a null string.