* Call Archive routine to move files from working directories to ThisBatchArchive_dir and compress.
* ArchiveFiles(pParameterList,JobName,Output_file,pThisBatchArchive_dir)
* The ArchiveFiles routine will figure out which files in which directories belong to each Job
*
* pParameterList is an array of the form pParameterList<1, n> = ParmName<n>, pParameterList<2, n> = ParmValue<n>
Ans = Screen Output(s) :Code as follow
Code: Select all
DEFFUN GetParam(aParameterList, vParmName) Calling "DSU.GetParam"
* pParameterList is an array of the form pParameterList<1, n> = ParmName<n>, pParameterList<2, n> = ParmValue<n>
vMsgInfo = "Routine: ArchiveFiles"
aDirList = ""
aDirNames = ""
vError = @FALSE
aAllScreenOutputs = ""
aParameterList = TRIM(pParameterList)
vJobName = TRIM(pJobName)
vOutputFile = TRIM(pOutputFile)
vThisBatchArchive_dir = TRIM(pThisBatchArchive_dir)
vListCt = DCount(aParameterList<1>, @VM)
* to test using the test button uncomment the following lines
vPlist = pParameterList
aParameterList = ""
Convert "," to @AM IN vPlist
vListCt = DCount(vPlist, @AM)
For ix = 1 to vListCt
aParameterList<1,ix> = field(vPlist<ix>,"=", 1)
aParameterList<2,ix> = field(vPlist<ix>,"=", 2)
Next ix
aAllScreenOutputs<-1> = "________________________________________________________"
aAllScreenOutputs<-1> = "Parameter List below contains ":vListCt:" params:":@AM:aParameterList
aAllScreenOutputs<-1> = "________________________________________________________"
vSystemType = GetParam(aParameterList, "SystemType")
If vSystemType = "NT" Then
cSlash = "\"
MKDIRcmd = "mkdir "
LScmd = "dir /b "
MOVEcmd = "move "
ZIPcmd = "pkzip "
CONVERT ":" TO "_" IN vJobName
End Else
vSystemType = "UNIX"
cSlash = "/"
MKDIRcmd = "mkdir -p "
LScmd = "ls "
MOVEcmd = "mv "
ZIPcmd = "gzip "
End
aNOArchive = DOWNCASE(GetParam(aParameterList, "NOArchive"))
CONVERT "," TO @AM IN aNOArchive
For iP = 1 to vListCt
vParmName = DOWNCASE(aParameterList<1,iP>)
LOCATE vParmName IN aNOArchive SETTING POS THEN
* * Skip the directories in aNOArchive list
END ELSE
Begin Case
Case Right(vParmName, 4) = "_dir" OR Right(vParmName, 9) = "directory"
vParmValue = aParameterList<2,iP>
vSlashCnt = DCOUNT(vParmValue, cSlash)
aDirList<-1> = vParmValue
aDirNames<-1> = field(vParmValue, cSlash, vSlashCnt - 1)
End Case
END
Next iP
vDirCt = DCount(aDirList, @AM)
aAllScreenOutputs<-1> = "Directory Names ":vDirCt:" rows:":@AM:aDirNames
aAllScreenOutputs<-1> = "Directory List ":vDirCt:" rows:":@AM:aDirList
aAllScreenOutputs<-1> = "________________________________________________________"
If vJobName = "" Then
aAllScreenOutputs<-1> = "NO JobName Passed - Required ArchiveFiles Routine parameter"
vError = @TRUE
End
If vThisBatchArchive_dir = "" Then
aAllScreenOutputs<-1> = "NO Archive directory Passed - Required ArchiveFiles Routine parameter"
vError = @TRUE
End
If vDirCt < 1 Then
aAllScreenOutputs<-1> = "NO source/target/work directories found in Parameter List"
vError = @TRUE
End
If vError Then
aAllScreenOutputs<-1> = "***NO files have been Archived***"
Call DSLogWarn(vMsgInfo:"ERROR - results:":@AM:aAllScreenOutputs, vMsgInfo:"ERROR")
Ans = 1
End Else
aCmd = ""
aCmd<-1> = MKDIRcmd:vThisBatchArchive_dir
aAllScreenOutputs<-1> = "***Archive Log***"
For iD = 1 to vDirCt
If vOutputFile <> "" Then
vSUBfile = vOutputFile
GOSUB SUBarchive
End
If vJobName <> "" Then
vSUBfile = vJobName
GOSUB SUBarchive
End
Next iD
Call DSLogInfo(vMsgInfo:"NORMAL - results:":@AM:aAllScreenOutputs, vMsgInfo)
Ans = 0
End
RETURN(Ans)
SUBarchive:
vCmd = LScmd:aDirList<iD>:vSUBfile:"*"
Call DSExecute(vSystemType, vCmd, pScreenOutput, pSystemReturnCode)
If vSystemType = "NT" Then
vCheckNoFiles = left(trim(pScreenOutput), 14)
End Else
vCheckNoFiles = trim(field(pScreenOutput,": ", 2))
vCheckNoFiles = trim(field(vCheckNoFiles,@AM, 1))
End
* Call DSLogInfo(vMsgInfo:"DEBUG - :":@AM:vCmd:@AM:pScreenOutput:@AM:"<":vCheckNoFiles:">", vMsgInfo)
If vCheckNoFiles = "No such file or directory" OR vCheckNoFiles = "File Not Found" Then
* aAllScreenOutputs<-1> = pScreenOutput
* aAllScreenOutputs<-1> = "--------------------"
* * skip it
End Else
aCmd<-1> = MKDIRcmd:vThisBatchArchive_dir:aDirNames<iD>
aCmd<-1> = MOVEcmd:aDirList<iD>:vSUBfile:"* ":vThisBatchArchive_dir:aDirNames<iD>
aCmd<-1> = ZIPcmd:vThisBatchArchive_dir:aDirNames<iD>:cSlash:vSUBfile:"* "
vCmdCnt = DCOUNT(aCmd, @AM)
FOR iC = 1 TO vCmdCnt
vCmd = aCmd<iC>
Call DSExecute(vSystemType, vCmd, pScreenOutput, pSystemReturnCode)
If pScreenOutput = "" Then pScreenOutput = "OK"
aAllScreenOutputs<-1> = vCmd
aAllScreenOutputs<-1> = pScreenOutput
aAllScreenOutputs<-1> = "--------------------"
NEXT iC
aCmd = ""
End