DGRL Posted March 13, 2018 Posted March 13, 2018 Dear coders I need a small routine to set a file's attribute (i.e. read-only or hidden ) As far as I know you need to use the Scripting.FileSystemObject but im not yet familiar with it And the same routine should be able to read the same file and give me back the attributes that are set The result of getting the att can also be in numbers i.e. 2 is only hidden and 1 is only read only 2081 = Read-only + Archiving + contents indexed + compressed Kind regards Quote
SLW210 Posted March 13, 2018 Posted March 13, 2018 What programing language are you trying to use? Quote
DGRL Posted March 13, 2018 Author Posted March 13, 2018 Sorry for not being specific lol *lisp is the language Quote
ronjonp Posted March 13, 2018 Posted March 13, 2018 Maybe this will get you started in the right direction: (defun _fileatts (file / f sfso) (cond ((and (findfile file) (setq sfso (vlax-get-or-create-object "Scripting.FileSystemObject"))) (setq f (vlax-invoke sfso 'getfile file)) (setq f (vlax-get f 'attributes)) (vlax-release-object sfso) f ) ) ) (_fileatts "G:\\Ron\\test.dwg") Quote
DGRL Posted March 13, 2018 Author Posted March 13, 2018 @ronjonp Thanks for this Do you also know how to set the atts? Quote
ronjonp Posted March 13, 2018 Posted March 13, 2018 This seems to work: (defun _readonly (file flag / f n sfso) (cond ((and (findfile file) (setq sfso (vlax-get-or-create-object "Scripting.FileSystemObject"))) (setq f (vlax-invoke sfso 'getfile file)) (setq n (vlax-get f 'attributes)) (cond (flag (and (/= 1 (rem n 32)) (vlax-put f 'attributes (1+ n)))) ((and (= 1 (rem n 32)) (vlax-put f 'attributes (1- n)))) ) (vlax-release-object sfso) ) ) ) ;; Set read only (_readonly "G:\\Ron\\test2.dwg" T) ;; Remove read only (_readonly "G:\\Ron\\test2.dwg" nil) Quote
Lee Mac Posted March 13, 2018 Posted March 13, 2018 Nice one Ron, though since the file attributes are bit-coded, I would suggest the following in place of your inner cond expression: (vlax-put f 'attributes (boole (if flag 7 4) 1 (vlax-get f 'attributes))) Quote
ronjonp Posted March 13, 2018 Posted March 13, 2018 Thanks for the example Lee. I knew there was a better way to do it but took the sledgehammer approach as I wasn't seeing it. Quote
BIGAL Posted March 14, 2018 Posted March 14, 2018 Batch file example of cleaning up my autocad temporary drive c: cd\ cd acadtemp del *.log del *.ac$ del {*.* del *.err del {*.* attrib etrans*.* -h del etrans*.* Quote
DGRL Posted March 14, 2018 Author Posted March 14, 2018 @everyone Thanks for the code's this is what I need. All are working fine 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.