> On Jul 10, 7:31am, Shelly Dixon wrote:
> > Subject: Copy question
> > Does anyone out there know how to copy a file (using the copy
> > command) and use the current date as part of the name? Is this
> > possible?
There were a couple of good suggestions, but I want to share a way to use
the POSIX name space and handle century dates. The most difficult part
of this example is parsing the various filename formats that can be passed in,
e.g., MPE unqualified, MPE fully qualified, POSIX absolute pathname, POSIX
relative pathname, etc. A way to convert an MPE filename to a POSIX pathname
is shown. This example works on 5.0:
-------------
PARM file
comment Date Copy: makes a copy of file with the current date (YYYMMDD)
comment appended to its equivalent POSIX name. Usage:
comment dcopy abc --> /ACCT/GROUP/ABC.YYYYMMDD 1
comment dcopy abc.efg --> /ACCT/EFG/ABC.YYYYMMDD 1
comment dcopy abc.efg.hij --> /HIJ/EFG/ABC.YYYYMMDD 1
comment dcopy ./abc --> ./abc.YYYYMMDD
comment dcopy /abc --> /abc.YYYYMMDD
comment dcopy /abc/def --> /abc/def.YYYYMMDD
comment dcopy .abc --> .abc.YYYYMMDD
comment
comment Notes: 1. POSIX names cannot exceed 16 characters when directly
comment under a MPE group, therefore the dot before the date is not
comment used if this would cause an overflow.
comment
comment Bugs: a) MPE file equations and system files ($oldpass) don't work
comment b) Inline MPE lockwords don't work
comment
comment Verify that "file" is a legal name and exists
if not finfo('!file", exist) then
echo "!file" does not exist.
return
endif
setvar CENTURY 19
setvar posixname (lft("!file",1) = "." or lft("!file",1) = "/")
comment Extract just the filename part from file
if posixname then
setvar target rht("!file",len("!file")-pos("/","!file",-1)) + "."
setvar qualify lft("!file",pos("/","!file",-1))
else
comment MPE name - convert to uppercase POSIX name
setvar target ups(lft("!file",pos(".","!file.",1)-1))
if pos(".","!file") = 0 then
setvar qualify "/!HPACCOUNT/!HPGROUP/"
elseif pos(".","!file") = pos(".","!file",-1) then
setvar qualify "/!HPACCOUNT/" + &
ups(rht("!file",len("!file")-pos(".","!file"))) + "/"
else
setvar qualify "/" + ups(rht("!file",len("!file")-pos(".","!file",-1)))+&
"/" + ups(str("!file",pos(".","!file")+1,&
pos(".","!file",-1)-pos(".","!file")-1)) + "/"
endif
if len(target) < 8 then
setvar target target + "."
endif
endif
comment
comment Now just append YYYYMMMDD to target and qualify it
copy !file, !qualify!target!CENTURY![rht("0!HPYEAR",2) + &
rht("0!HPMONTH",2) + rht("0!HPDATE",2)]
---------
regards,
Jeff Vance, CSY
--
|