Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

read-only file

6 REPLIES 6
Reply
Message 1 of 7
Anonymous
749 Views, 6 Replies

read-only file

is there a way to check if a file is read-only or locked from autolisp?
6 REPLIES 6
Message 2 of 7
Anonymous
in reply to: Anonymous

If you want to check for writabilty:
(if(Setq FD1 (open FILENAME "w"))......

OR if you use doslib, something like (dos_openp FILENAME) or(dos_attrib [filespec [bits]]) might be worth a look.

Dean
Message 3 of 7
Anonymous
in reply to: Anonymous

Joe,
If you have the doslib2k.arx loaded..

One way is to do:
(setq z (cdr (car (dos_attrib "c:\\acad\\test.txt"))))
..
where "c:\\acad\\test.txt" is the filename you want to check.
..
(if (= z 0); file is 'normal' mode
(if (> z 0); file has some attrib set other than normal
(if (= z 8); file is 'read-only'
(if (= z 9); file is 'archive' and 'read-only'

This should get you started.

Bob
Message 4 of 7
Anonymous
in reply to: Anonymous

Hi, You should use a) activeX extension of visual lisp b) go to ACADX.com (very good) there are some examples for using windows scripting host with Visual Lisp. Using scripting host it's easy to read the file properties Regards Dieter Example based upon the work from acadx.com (it's now time to return something) ;;; test fileproperties ;;; returns T if ;;; a) file exists ;;; b) file can be accessed -> not read only ;;; PARAMETER: ;;; fso -> filesystem object created by calling function ;;; fname -> filename ;;; show-errmessage -> see below (defun fs:test-fileproperties ( fso fname show-errmessage / GetFileName GetFile file-attributes file-exist getfile-obj FileOK readonly ) (setq file-exist (vlax-invoke-method fso 'FileExists fname) FileOK nil) (if (= file-exist :vlax-true) (progn (setq getfile-obj (vlax-invoke-method fso 'GetFile fname ) file-attributes (vlax-get-property getfile-obj 'attributes) FileOK T) (if (= 1 (check_bit bit_test file-attributes 0)) (progn (setq FileOK nil readonly T) )) (vlax-release-object getfile-obj) )) ;;; show-errmessage = 0 -> no errormessage at all ;;; 1 -> errormessage in commandwindow ;;; 2 -> errormessage by menue (cond (( = 1 show-errmessage) (or FileOK (and readonly (princ (strcat "\n file " fname " is write protected!")) ) );;; or FileOK ) (( = 2 show-errmessage) (or FileOK (and readonly ;;; use acad error message or write your own (princ "\nFile is readonly") ) );;; or FileOK ) ) FileOK );;; end defun ;;; utility function to test which bit is set ;;; I use it for testing even or odd number testing as well ;;; bit zero = 0 == even ;;; Number must be of type integer (defun check_bit (bit_test Maske bit / tmp_bit_test) (if (/= 0 (logand Maske (expt 2 bit))) ;; bit set, return 1 (setq tmp_bit_test 1) (setq tmp_bit_test 0) ) tmp_bit_test );;---- end defun -------- Joe wrote: > is there a way to check if a file is read-only or locked from autolisp? > > >
Message 5 of 7
Anonymous
in reply to: Anonymous

Why not vl-file-systime?
Message 6 of 7
Anonymous
in reply to: Anonymous

sorry Joe, I forgot in that posted code that you have to get the file-system object by calling (setq fso (vlax-create-object "scripting.filesystemobject")) Thats the parameter "fso" passed in (fs:test-fileproperties fso ....) Don't forget to check if fso was created. More help about the file object and related information under ACAD may be obtained by starting Extras-> Macros-> Visual-Basic-Editor Start Help within VBA-Editor Search for "file" and read.... Best regards Dieter Joe wrote: > is there a way to check if a file is read-only or locked from autolisp? > > >
Message 7 of 7
Anonymous
in reply to: Anonymous

In article <403bbe35$1_2@newsprd01>, none@yahoo.com says... > is there a way to check if a file is read-only or locked from autolisp? If you are talking about the current DWG that's loaded, then check out the WRITESTAT system variable. If you are talking about any file on disk, looks like you've got enough other replies to keep you busy so I won't bother to add my $0.02 there. -- Darren J. Young CAD/CAM Systems Developer Cold Spring Granite Company 202 South Third Avenue Cold Spring, Minnesota 56320 Email: dyoung@coldspringgranite.com Phone: (320) 685-5045 Fax: (320) 685-5052

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost