PDA

View Full Version : Lock file


GiorgioL
01-13-2004, 02:58 AM
A ME10 macro update a PDF file but the PDF file is opened by Acrobat Reader in other PC in the factory.
How I check if the file is free to be updated or not.

Any suggestion?

Regards. GiorgioL.

clausb
01-13-2004, 09:54 AM
Rough idea of somebody (=me) who almost never writes ME10 macros:

Use TRAP_ERROR to disable the standard error handling
Try to open the file
Use CHECK_ERROR to find out whether the file could actually be opened
If yes, just use the file. If no, display an error message to the user, or wait a while and retry, or...


Claus

John Scheffel
01-13-2004, 11:27 AM
The suggestion from Claus is how I would do it. Here is some sample code similar to macros we use to test file existence.

DEFINE Check_PDF_file
TRAP_ERROR
OPEN_INFILE 1 'file.pdf' END
IF (CHECK_ERROR)
DISPLAY 'PDF File in use, cannot update'
ELSE
CLOSE_FILE 1
{Call your PDF update macro here}
END_IF
END_DEFINE

GiorgioL
01-14-2004, 01:57 AM
Thanks John,

I was writing almost the same macro.
I understand the macro but if the PDF file is opened with ACROBAT reader it will answer "you can update the PDF file".

The OPEN_INFILE function open a file in read mode and answer always OK also if the file is locked with ACROBAT (locked with acrobat means that someone is viewing the file in someplace).

To understand if the file is locked we need use the OPEN_OUTFILE function and change the row with:

open_outfile 1 append "file.pdf" end

The cons is that a file is created (0 size) if is not present.

Regards, GiorgioL.

clausb
01-14-2004, 02:22 AM
>The cons is that a file is created (0 size) if is not present.

If you don't like that behavior, open the file for reading first. If it does not exist, then it cannot be locked, so you can now either open it for writing now or report the fact to the user.

If the file exists, close it, then re-open it for writing. If this causes an error, tell the user that the file is locked by somebody else, otherwise write to it.

Claus

GiorgioL
01-14-2004, 06:05 AM
Claus,

I agree with you. A double check avoid the cons.

Thank for the help. Regards. Giorgio L.