Aftertouch Posted October 21 Posted October 21 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? Quote
Steven P Posted October 21 Posted October 21 (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 October 21 by Steven P Quote
Aftertouch Posted October 21 Author Posted October 21 @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 ) 1 Quote
Steven P Posted October 21 Posted October 21 Ahh, i missed a closing ) - edited above and it should work now Quote
Recommended Posts
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.