Kbase P127216: 4GL: How to maintain the last four versions of a given file?
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  11/28/2007 |
|
Status: Unverified
GOAL:
4GL: How to maintain the last four versions of a given file?
GOAL:
How to back up the last four versions of a file based on the file reaching a given size?
FACT(s) (Environment):
All Supported Operating Systems
Progress 8.x
Progress 9.x
OpenEdge 10.x
FIX:
The following procedure examines the size of an existing file named LogFileName.txt. If the size exceeds the preset value iMaxFileSize, set to 6000 bytes in the sample, it backs it up to a new file whose name is of the form LogFileName00x.txt ( where x = 1, 2, 3 or 4) and empties the file LogFileName.txt. If all these files already exist, then it will delete the oldest one LogFileName001.txt and rename the files according to their age, LogFileName001.txt being the oldest and LogFileName004.txt being the newest and empties the file LogFileName.txt:
DEFINE VARIABLE cDirectoryName AS CHARACTER NO-UNDO.
DEFINE VARIABLE cLogFileName AS CHARACTER NO-UNDO.
DEFINE VARIABLE cEmptyFileName AS CHARACTER NO-UNDO.
DEFINE VARIABLE cNewFileName AS CHARACTER NO-UNDO.
DEFINE VARIABLE iMaxFileSize AS INTEGER NO-UNDO.
DEFINE VARIABLE iFileCount AS INTEGER NO-UNDO.
DEFINE VARIABLE lBackedUp AS LOGICAL NO-UNDO.
ASSIGN
cDirectoryName = "C:\Temp"
cLogFileName = "LogFileName.txt"
cLogFileName = cDirectoryName + "\" + cLogFileName
cEmptyFileName = "EmptyFile.txt"
cEmptyFileName = cDirectoryName + "\" + cEmptyFileName
iMaxFileSize = 6000.
/* Create an empty file */
OUTPUT TO VALUE(cEmptyFileName).
OUTPUT CLOSE.
IF SEARCH(cLogFileName) <> ? THEN
ASSIGN
FILE-INFO:FILE-NAME = SEARCH(cLogFileName).
IF FILE-INFO:FILE-SIZE > iMaxFileSize THEN DO:
DO iFileCount = 1 TO 4:
cNewFileName = cDirectoryName + "\" + "LogFileName" + STRING(iFileCount, "999") + ".txt".
IF SEARCH(cNewFileName) = ? THEN DO:
RUN BackItUp.
lBackedUp = TRUE.
LEAVE.
END.
END.
IF NOT lBackedUp THEN RUN ReCycleNames.
END.
/* Delete the empty file */
OS-DELETE VALUE(cEmptyFileName).
PROCEDURE BackItUp:
OS-COPY VALUE(cLogFileName) VALUE(cNewFileName).
OS-COPY VALUE(cEmptyFileName) VALUE(cLogFileName).
END PROCEDURE.
PROCEDURE ReCycleNames:
DEFINE VARIABLE cSourceFileName AS CHARACTER NO-UNDO.
DEFINE VARIABLE cTargetFileName AS CHARACTER NO-UNDO.
DEFINE VARIABLE iSourceFileNum AS INTEGER NO-UNDO.
DEFINE VARIABLE iTargetFileNum AS INTEGER NO-UNDO.
DO iFileCount = 2 TO 4:
ASSIGN
iSourceFileNum = iFileCount
iTargetFileNum = iFileCount - 1
cSourceFileName = cDirectoryName + "\" + "LogFileName" + STRING(iSourceFileNum, "999") + ".txt"
cTargetFileName = cDirectoryName + "\" + "LogFileName" + STRING(iTargetFileNum, "999") + .".txt".
OS-COPY VALUE(cSourceFileName) VALUE(cTargetFileName).
END.
OS-COPY VALUE(cLogFileName) VALUE(cSourceFileName).
OS-COPY VALUE(cEmptyFileName) VALUE(cLogFileName).
END PROCEDURE..