Kbase P97827: How to periodically check for and process a given file is in a given directory at specified time in
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  11/19/2004 |
|
Status: Unverified
GOAL:
How to periodically check for and process a given file is in a given directory at specified time intervals in batch mode?
FIX:
The following procedure runs in the background and scans a specified directory for a specified file at specified time intervals. Every time the file is found, the procedure performs the following tasks:
1. Increment a session file counter
2. Rename the file using the session file counter.
3. Append the newly generated file name to a log.
To run this sample procedure in batch mode on Windows platforms, execute the command:
prowin32.exe -b -p FileMonitor.p
To run this program in batch mode on Linux/UNIX platforms, execute the command:
bpro -b -p FileMonitor.p
/************ Procedure FileMonitor.p **************/
DEFINE VARIABLE cFileName AS CHARACTER NO-UNDO.
DEFINE VARIABLE cDiretoryName AS CHARACTER NO-UNDO.
DEFINE VARIABLE iFileNumber AS INTEGER NO-UNDO.
DEFINE VARIABLE iTimeInterval AS INTEGER NO-UNDO.
/* Initialize variables */
ASSIGN
cFileName = "test.txt"
cDiretoryName = "."
iFileNumber = 0
iTimeInterval = 5.
/* Start the background process */
REPEAT:
RUN Processfile.
PAUSE iTimeInterval.
END.
PROCEDURE Processfile.
OUTPUT TO mylog.txt APPEND.
IF SEARCH(cFileName) = (cDiretoryName + "\" + cFileName) THEN DO:
iFileNumber = iFileNumber + 1.
OS-RENAME VALUE(cFileName) VALUE(cFileName + STRING(iFileNumber, "9999999")).
PUT UNFORMATTED "File" + STRING(iFileNumber, "9999999") + ".txt" SKIP.
OUTPUT CLOSE.
END.
END PROCEDURE.