I would NOT try open for write... because it may work, lock out others, and change the revision date/count.
Instead just try $OPEN/READ/SHARE=READ FILE ...
If it opens, you can actually use the file handle to read the data, thus preventing an other process from (re-)opening it between the test and usage.
But it will be using DCL IO which uses a small buffer.
The example below shows this for mostly for fun: APPEND FILE ...
The example hard-codes an output mostly because I was lazy.
You are better of just closing the file on success first and then use the APPEND/LOG.
Enjoy,
Hein
$ output = "tmp.tmp"
$ if p1.eqs."" then exit 16
$ create tmp.tmp
$ old = ""
$loop:
$ file_name = f$search(p1)
$ if file_name .eqs. "" .or. file_name .eqs.old then exit
$ old = file_name ! Handle non-wildcarded input
$ close/nolog file
$ open/read/share=read/erro=locked_or_other_error file 'file_name'
$ append file tmp.tmp ! /log
$ write sys$error "Appended ", file_name
$ close/nolog file
$ goto loop
$locked_or_other_error:
$ write sys$error "Found, but could not open file ", file_name
$ goto loop