The Question is:
I am doing a copy using a pattern match with a /exclude switch and a single
A file that fits the exclude pattern is locked and generates a copy-e-openin
error which triggers our error handling.
We want to keep the error handling intact in case any of our target files are
locked or have another problem. Why does the Copy command care if an excluded
file is locked? More to the point how can I stop it causing the copy to be
reported as an error (ev
en though the copy actually successfully completes).
The Answer is :
DCL file selection and exclusion is fairly complex as it can involve the
file name, any of the dates and/or the owner. The code is common to a large
number of DCL commands.
DCL first OPENs the file in case it needs to test any of the information
in the header. Granted, in your specific case, this is not necessary, but
nevertheless, this is how it is implemented. There are obviously other
possible implementations which may behave better in some circumstances,
but there are significant benefits in commonality and generality.
The status of a DCL command is returned as a single longword. By convention,
this is the "worst" condition that was encountered by the command or utility.
In your case the -RMS-E-FLK condition obscures the %COPY-S-COPIED conditions.
There are a any number of ways you could deal with this. For example, if
your objective is to ensure that SOME files were created you could use the
PIPE and SEARCH commands to verify some successes. For example:
$ PIPE COPY/LOG 'source'/EXCLUDE='exclude' 'target' | -
SEARCH SYS$PIPE "$COPY-S-COPIED" ; -
DEFINE/JOB/NOLOG STATUS &$STATUS
Another possibility is to use the DIRECTORY command to select the files
and pipe the output into a DCL loop that performs the COPY. For example:
$ ! P1=input filespec
$ ! P2=exclude filespec
$ ! P3=output filespec
$ ! P4=flag (internal use)
$ SET NOON
$ IF P4.NES."" THEN GOTO 'P4'
$ PIPE DIRECTORY/NOHEAD/NOTRAIL/COLUMN=1 'p1'/EXCLUDE='p2' | -
@'self' "''p1'" "''p2'" "''p3'" "DOCOPY"
$ READ/END=Finish SYS$PIPE file
$ COPY/LOG 'file' 'p3'
$ GOTO DOCOPY
$ Finish: EXIT
Provision of error detection/accumulation is left as an exercise.