HP OpenVMS Systemsask the wizard |
The Question is: Is it possible to use a wildcard rename to remove suffixes from extended filenames with multiple suffixes, e.g., ren *.p.z *.p_z changes file.p.z to file.p.p_z . what I'd like to get is file.p_z . The rename/wildcard behavior is one of my favorite vms features.and I' d like to be able to use in these cases, too. Thanks. Corinne James The Answer is :
The OpenVMS Wizard will assume that this involves files on an ODS-5
disk.
The semantics you request would mean that the wild card character in the
output filespec would have to mean "the string matched by the wildcard
in the input filespec". This is the behaviour of the DOS RENAME
command.
The OpenVMS Wizard agrees that this could be a useful feature, however
it cannot be easily implemented within the OpenVMS wildcard framework.
As OpenVMS permits multiple wildcards in filespecs, there is no way from
the output filespec to refer to particular wildcard matched strings from
the input filespec. DOS gets away with it because it only permits a single
wildcard in a filespec, thus there is no ambiguity as to which string is
referred from the output filespec.
So, without implementing some kind of parameter-based syntax for matching
and selecting wildcard strings, it's not possible to implement these
semantics within the RENAME or COPY commands. Given the necessary
complexity of such a syntax, and its reasonably limited application
(however useful!), the Wizard feels it unlikely DCL would be changed
to include this kind of function.
What OpenVMS does implement is a wildcard that replaces an entire chunk
of a filename. With ODS-5, the last "chunk" after the period is the
file extension chunk (well, the last chunk that isn't also the file
version), with the rest being the filename. Partial-field replacements
based on wildcards are not permitted -- you can only replace the entire
field -- for reasons cited above.
On the other hand, this type of RENAME operation is easily achieved with
a short DCL command procedure. For example:
REN.COM
$ LOOP: F=F$SEARCH("*.p.z")
$ IF F.EQS."" THEN EXIT
$ new=F$PARSE(f,,,"NAME")-"^.P"+".p_z"
$ RENAME 'f' 'new'
$ GOTO loop
For a more general solution, here is a procedure which will take a
wildcard filespec and RENAME any files with multiple "."'s in the file
name so that the filetype starts at the first "." and all subsequent
"."'s are replaced with "_"
RENAME_MULTIPLE_SUFFIX.COM
$ IF p1.EQS."" THEN INQUIRE p1 "Filespec"
$ loop:
$ f=F$SEARCH(p1)
$ IF f.EQS."" THEN EXIT
$ fname=F$PARSE(f,,,"NAME")
$ l=F$LOCATE("^.",fname)
$ IF l.LT.F$LENGTH(fname)
$ THEN
$ ftype=F$EXTRACT(l+2,F$LENGTH(fname),fname)
$ fname=F$EXTRACT(0,l,fname)
$ loop1:
$ l=F$LOCATE("^.",ftype)
$ IF l.LT.F$LENGTH(ftype)
$ THEN
$ ftype=F$EXTRACT(0,l,ftype)+"_"+-
F$EXTRACT(l+2,F$LENGTH(ftype),ftype)
$ GOTO loop1
$ ENDIF
$ ftype=ftype+"_"+(F$PARSE(f,,,"TYPE")-".")
$ RENAME/LOG 'f' 'fname'.'ftype'
$ ENDIF
$ IF F$EDIT(f,"UPCASE").NES.F$EDIT(F$PARSE(p1,f),"UPCASE") THEN GOTO loop
Tools such as Perl can also perform various sorts of search-and-replace
operations, and may be of interest here.
|