Jump to content

Recommended Posts

Posted

Hi all,

 

I am having some issues with a PLOT function.

when a PDF is in use by 'somebody' and i want to overwrite it, i cannot seem to detect the 'lock' on the file.

this causes my program to crash.

 

Is there a way to check if a PDF is in use/can be overwritten?

Posted (edited)

I think this is it:

 

Result is Yes, No or New, 'Yes' PDF is currently open, 'No', it exists and is closed, 'New' PDF file doesn't exist

 

(defun PDFOpened( PDFFilename / PDFO)

  (if (findfile PDFFilename) ;; Full file path & name
    (progn
      (if (vl-file-rename PDFFilename PDFFilename)
        (setq PDFO "No")  ;;file is closed
        (setq PDFO "Yes") ;;file is open
      ) ; end if
    ) ; end progn
    (progn
      (setq PDFO "New")
    ) ; end progn
  ) ; end of
  PDFO
)

 

Edited by Steven P
Posted

@Steven P

The code gave me some odd behaviour due to this:

Note: If the target file already exists, this function fails.

 

Managed to solve it with this function for now:

 

(defun is-file-locked (file-path)
  (setq file (open file-path "w")) ; Try to open the file in write mode
  (if file
    (progn
      (close file) ; If successful, close the file
      nil) ; Not locked
    t) ; If failed, it is locked
)

 

  • Like 1
Posted

Ahh, i missed a closing ) - edited above and it should work now

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...